PHP mail()附件问题

PHP mail()附件问题,第1张

PHP mail()附件问题
$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_enpre($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 enpred 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 messageif (mail($to, $subject, $body, $headers)) {    echo "mail send ... OK";} else {    echo "mail send ... ERROR";}

我所做的:

  • 将主体与标题分离
  • 删除了放在分隔符之前的多余EOL


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5641398.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存