【发布时间】:2011-09-10 15:07:45
【问题描述】:
谁能帮我弄清楚为什么这总是返回错误?
$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."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
// send message
if (mail($to, $subject, "", $headers)) {
echo "mail send ... OK";
} else {
echo "mail send ... ERROR";
}
【问题讨论】:
-
几天前我看到了“将所有内容放入
$headers”。你们是从哪里复制粘贴的? -
这种手动标题操作是一个肮脏的解决方案。我个人是 Zend_Mail 的粉丝,虽然我想知道任何其他“智能”方法。
-
@MattH.,Zend 开发人员也不必做这种“肮脏的解决方案”吗?
标签: php email attachment