phpmailer如何保存文本格式

时间:2013-10-12 08:42:02

标签: php

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

1 个答案:

答案 0 :(得分:0)

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

$ headers。=“Content-Type:text / html; charset = iso-8859-1 \ r \ n”;   $ headers。=“Content-Transfer-Encoding:8bit \ r \ n”;   $ headers。=“”。$ message。“\ n”;   $ headers。=“ - ”。$ num。“\ n”;

第三行应该阅读

$ headers。=“\ r \ n”。$ message。“\ n”;

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