2011-08-31 125 views
3

我使用PHP发出多部分/混合消息(纯文本,html和附件)。然而,虽然它适用于大多数帐户,雅虎,GMail和Sky似乎显示空白的电子邮件。其他所有内容似乎都显示电子邮件。任何帮助将不胜感激!空白多部分电子邮件

我的头是

$headers .= "Content-Type: multipart/mixed; boundary=\"mixed-" . $random_hash . "-mixed\"\n"; 
$headers .= "MIME-Version: 1.0\n"; 

和内容是;

--mixed-7df05b31-mixed 

Content-Type: multipart/alternative; boundary="alt-7df05b31-alt" 

--alt-7df05b31-alt 

Content-Type: text/plain; charset=utf-8 

      Hello how are you? I am just checking the mailing function. 

      Hopefully this will work! 

      Cheers. 

--alt-7df05b31-alt 

Content-Type: text/html; charset=utf-8 

<div style="font-family:Arial, Helvetica, sans-serif; font-size: 10pt;"> 

<div> 


      Hello how are you? I am just <b>checking</b> the mailing function.<br><br> 


      Hopefully this will work!<br><br> 


      Cheers.</div></div> 

--alt-7df05b31-alt-- 

--mixed-7df05b31-mixed 

Content-Type: text/plain; name="abc.txt" 
Content-Disposition: attachment; filename="abc.txt" 
Content-Transfer-Encoding: base64 

SEVMTE8gSlVTVCBURVNUSU5HIC4uLiA= 

--mixed-7df05b31-mixed-- 

回答

0

请勿构建您自己的MIME消息。使用SwiftmailerPHPMailer为你做。

+3

构建自编译的MIME消息有什么问题? –

+0

,因为你显然做错了什么。如果您的电子邮件构建得当,它会显示在Gmail /雅虎没有麻烦 - 我还没有看到PHPMailer在我的所有项目中引起格式错误的消息,无论它在哪里读取。 –

+0

PHPMailer似乎工作 - 所以会坚持。 –

2

它可能是粘贴的工件,但尝试删除每个边界末端的空白区域。 (突出显示文字,你会注意到边界有额外的空间,但最后的边界 - 不)

2

请验证你的代码是否如下所示,因为以下代码对我来说工作正常。

$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
$headers .= "This is a multi-part message in MIME format.\r\n"; 
$headers .= "--".$uid."\r\n"; 
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n"; 
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
$headers .= $msg."\r\n\r\n";  
$headers .= "--".$uid."\r\n"; 
$headers .= "Content-Type:application/html; name=\"".$filename."\" \r\n"; // use different content types here 
$headers .= "Content-Transfer-Encoding: base64\r\n"; 
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 
$headers .= $content."\r\n\r\n"; 
$headers .= "--".$uid."--";