无法通过移动电子邮件打开电子邮件(网络邮件)附件

时间:2016-06-30 14:58:41

标签: php email mobile

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

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

$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";
}

1 个答案:

答案 0 :(得分:0)

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

Content-Disposition: attachment; filename=...