$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers = "From: $from";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . strip_tags($content) . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<2;$x++)
{
$data = chunk_split($att[$x]);
$message .= "Content-Type: {\"application/pdf\"};\n" . " name=\"$name[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$name[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
答案 0 :(得分:0)
IMO解决方案不是修复你的代码。
我的建议是使用已经可用于PHP的众多非常好的电子邮件库之一,例如SwiftMailer或PHPMailer。由于各种电子邮件客户端/站点的所有细微差别,编码电子邮件是一项非常棘手的任务,并且已经对这些库进行了相当全面的测试。现有的库还包括有助于降低电子邮件在目的地被标记为垃圾邮件的可能性的功能。