发送电子邮件文本/html 失败


Sending email text/html fails

我正在尝试发送和通过电子邮件发送文本或/和html版本。

我所做的是这样的:

 $bodyHTML = "
 --PHP-alt-$random_hash 
 Content-Type: text/plain; charset='iso-8859-1' 
 Content-Transfer-Encoding: 7bit
http://example.com/app_dl.php?app_id=$_GET[app_id] to download your $app_name app 'n'r
Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example' 'n'r'n'r
example.com team
  --PHP-alt-$random_hash 
 Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
 <p><a href='http://example.com/app_dl.php?app_id=$_GET[app_id]'>Click Here</a> to download your $app_name app</p>
 <p>Want to get tons more hot apps for free! anywhere anytime? Download our app on <a href='http://example.com'>example.com</a></p>
 <br/>
 <p>example.com team</p>
  --PHP-alt-$random_hash ";
endif;

这就是我得到的:

--PHP-alt-f4b83c7072ae970392b44308a6c36109 Content-Type: text/plain; charset='iso-8859-
    1' Content-Transfer-Encoding: 7bit http://example.com/app_dl.php?app_id=35 to download your PhoneMates app Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example.com' example.com team --PHP-alt-f4b83c7072ae970392b44308a6c36109 Content-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit
        Click Here to download your PhoneMates app
        Want to get tons more hot apps for free! anywhere anytime? Download our app on example.com
   example.com team
    --PHP-alt-f4b83c7072ae970392b44308a6c36109  

问题是我看到了所有这些标题行。内容类型..并且文本行的格式无法设置为"'''r"。

另外,我不知道我是否可以达到如果一个版本失败..html或txt,则会出现另一个版本的效果..感谢您的帮助

以下是一些代码:

 $random_hash = md5(date('r', time())); 
 $boundary="PHP-alt-".$random_hash;
 $headers = array ('From' => $from,
  'Content-Type'=>  'multipart/alternative',
   'boundary'=>$boundary,  
   'To' => $to,
    'Return-Path' => 'info@example.com',
   'Subject' => $subject);

其他详细信息,例如发件人,通行证,标题,,不相关。所以我没有在这里展示它们..

不要滚动自己的 MIME 处理。使用库而不是重新发明轮子。

我知道 Swift 是 PHP 领域的常用选择。

也就是说,我怀疑问题与 MIME 边界标记和标题之前的空格有关。尝试将其删除。

此外,您的最后一个 MIME 边界缺少末尾的--

真的,真的,使用一个强大的,经过良好测试的第三方库来做这些东西。有太多繁琐的东西,你可能会出错。

当我编写自己的标题时,就像你现在所做的那样,这是最后一组标题,最终成为正确的工作设置。

//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0'r'n";
$headers .= "From:".$from."'r'n";
$headers .= "To: ".$to."'r'n";
$headers .= "Return-Path: ".$from."'r'n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "'r'n";

此外,我的边界在上下文中如下所示:

$message .= "'r'n'r'n--" . $boundary . "--";

大概,你需要那些尾随破折号。