无法从移动电子邮件打开电子邮件(Web-mail)附件



我发送了一封包含附件的邮件。当我把邮件发送到gmail账户时,它在手机和电脑上都能正常工作,但当我把同样的邮件发送到网络邮件账户时,我可以在电脑上查看表格并下载附件(松鼠),但附件无法从我的内置手机应用程序(电子邮件)中下载。附件完全可见,文件大小也匹配,但在手机上无法打开。我正确地使用了代码,这已经是一个问题的答案。

我的代码格式正确,如下所示:

$to = "myemail@mydomain.com";
$from = "Website <website@mydomain.com>";
$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";
}

附件部分可能缺少文件名:

Content-Disposition: attachment; filename=...

最新更新