以下代码在发送到 GMAIL、YAHOO、HOTMAIL 时保留消息格式,但在通过 Outlook 或 Mozilla Thunderbird 访问时显示空消息时相反。
我试过 N2blr 但它给出了正确的结果。
任何想法?
$fp = fopen($attachment_temp, "rb");
$file = fread($fp, $attachment_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers
$headers = "From: ".$namefrom."<".$mailhost.">\r\n";
$headers .="Reply-To: ".$emailfrom."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$attachment_type." ";
$headers .= "name=\"".$attachment_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$attachment_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";