我对这个问题很头疼,我不知道是否有任何1可以帮助我。在我的测试和BCC中,我总能正确看到PDF附件,但也许有10%的人将PDF文件视为已损坏(我知道有些人使用Outlook,我正在使用Mac邮件)。PHP邮件PDF附件获取文件损坏
function mail_attachment($content, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = "Invitation.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $content;
$attachment = chunk_split(base64_encode($pdfdoc));
// main header
$headers = "From: Myself <".$from_mail.">\nBCC: [email protected]".$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed;{$eol}\tboundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"utf-8\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message;
$body .= $eol.$eol;
// message
$body .= "Content-Type: text/plain; charset=\"utf-8\"".$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.$eol;
// send message
$em = mail($mailto, $subject, $body, $headers);
return $em;}
可能发生了什么?我总是看到它的工作,但很少有人无法打开文件..
使用[swiftmailer.org(http://swiftmailer.org/)和你的生活会更容易;) –
我建议你[PHPMailer的( https://github.com/Synchro/PHPMailer)。 – Nelson
,我可以从html2pdf输出附上pdf吗? –