0

以下代码在发送到 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."--";
4

1 回答 1

0

在我看来这里有一个错误:

$headers .= "内容类型: text/html; charset=iso-8859-1\r\n"; $headers .= "内容传输编码:8bit\r\n"; $headers .= "".$message."\n"; $headers .= "--".$num."\n";

第三行应该读

$headers .= "\r\n".$message."\n";

即使某些服务器能够从此类错误中恢复。此外,您可能希望从 ISO-8859-1 迁移到 UTF-8 以获得更完整的国际化支持。

于 2013-10-12T09:32:22.777 回答