发送电子邮件和在PHP中构建Mimes

时间:2012-05-10 05:43:54

标签: php email

我正在发送一封带有php的电子邮件。这些是我的标题。

$headers = array (
'MIME-Version' => '1.0',
'From' => $from,
'To' => $to,
'Return-Path' => 'info@example.com',
'Content-Type'=>  'multipart/alternative',
'boundary'=>$boundary,  
'Subject' => $subject);

 $random_hash = md5(date('r', time())); 

那是我的html / textbody:

    $bodyHTML = "
 --PHP-alt-$random_hash 
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: 7bit
http://example.com/app_dl.php?app_id=$_GET[app_id] to download your $app_name app \n\r\n\r
Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example.com' \n\r\n\r
example.com team
--PHP-alt-$random_hash 
Content-Type: text/html; charset=utf-8
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--";

我长期以来一直坚持这个问题,现在..我错过了什么

1 个答案:

答案 0 :(得分:1)

尝试删除前导空格并添加换行符:

    $boundary = "PHP_alt_$random_hash";
    $bodyHTML = "--$boundary
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: 7bit

http://example.com/app_dl.php?app_id=$_GET[app_id] to download your $app_name app \n\r\n\r
Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example.com' \n\r\n\r
example.com team

--$boundary 
Content-Type: text/html; charset=utf-8
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>

--$boundary--";