2016-06-30 88 views
-1

我發送了一封郵件,其中包含一個和一個附件。當我將郵件發送到Gmail帳戶時,它在移動設備和PC上都能正常工作,但是當我將同一封郵件發送到網絡郵件帳戶時,我可以查看錶格並將附件下載到PC(松鼠)上,但是無法從我的內置移動應用程序(電子郵件)下載附件。附件完全可見,文件大小也匹配,但無法在移動設備上打開。我正確使用了代碼,這已經是一個問題的發佈回答。電子郵件(網絡郵件)附件無法從移動電子郵件打開

我的代碼格式是正確的,如下圖所示:

$to = "[email protected]"; 
$from = "Website <[email protected]>"; 
$subject = "Test Attachment Email"; 

$separator = md5(time()); 

// carriage return type (we use a PHP end of line constant) 
$eol = PHP_EOL; 

// attachment name 
$filename = "document.pdf"; 

//$pdfdoc is PDF generated by FPDF 
$attachment = chunk_split(base64_encode($pdfdoc)); 

// main header 
$headers = "From: ".$from.$eol; 
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\""; 

// no more headers after this, we start the body! // 

$body = "--".$separator.$eol; 
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; 
$body .= "This is a MIME encoded message.".$eol; 

// message 
$body .= "--".$separator.$eol; 
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; 
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol; 
$body .= $message.$eol; 

// attachment 
$body .= "--".$separator.$eol; 
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$body .= "Content-Transfer-Encoding: base64".$eol; 
$body .= "Content-Disposition: attachment".$eol.$eol; 
$body .= $attachment.$eol; 
$body .= "--".$separator."--"; 

// send message 
if (mail($to, $subject, $body, $headers)) { 
    echo "mail send ... OK"; 
} else { 
    echo "mail send ... ERROR"; 
} 

回答

0

有可能是一個文件名中的附件部分丟失:

Content-Disposition: attachment; filename=... 
+0

號我已經有了一部分。 –

+0

只需在附件部分查看附件 –