2013-03-03 29 views
0

我嘗試發送一個多部分/替代電子郵件,所以我發送一個文本版本和一個HTML版本在一個單一的郵件。我的問題是,郵件只包含這個純文本:MIME PHP郵件只顯示文本/純文本

郵件是在這裏:

Multipart Message coming up 

--b4d67c224c82d8fad38c0bcef1a0bf97Content-Type: text/plain; charset=iso-8859-1Content-Transfer-Encoding: 7bitYou really ought remember the birthdays--b4d67c224c82d8fad38c0bcef1a0bf97Content-Type: text/html; charset=iso-8859-1Content-Transfer-Encoding: 7bit<html> 
     <head> 
      <title>Birthday Reminders for August</title> 
     </head> 
     <body> 
      <p>Here are the birthdays upcoming in August!</p> 
     </body> 
     </html> 
     --b4d67c224c82d8fad38c0bcef1a0bf97-- 

的代碼如下所示。

<? 

//this is a path to PHP mailer class you have dowloaded 
$to  = "[email protected]"; 

$boundary = md5(date('U')); 

$subject = "My Subject"; 

$headers = "From: [email protected]" . "\r\n". 
      "X-Mailer: PHP/".phpversion() ."\r\n". 
      "MIME-Version: 1.0" . "\r\n". 
      "Content-Type: multipart/alternative; boundary=$boundary". "\r\n". 
      "Content-Transfer-Encoding: 7bit". "\r\n"; 

$text = "You really ought remember the birthdays";  
$html = '<html> 
    <head> 
     <title>Birthday Reminders for August</title> 
    </head> 
    <body> 
     <p>Here are the birthdays upcoming in August!</p> 
    </body> 
    </html> 
    '; 

$message = "Multipart Message coming up" . "\r\n\r\n". 
     "--".$boundary. 
     "Content-Type: text/plain; charset=iso-8859-1" . 
     "Content-Transfer-Encoding: 7bit". 
     $text. 
     "--".$boundary. 
     "Content-Type: text/html; charset=iso-8859-1". 
     "Content-Transfer-Encoding: 7bit". 
     $html. 
     "--".$boundary."--"; 

mail($to, $subject, $message, $headers); 

?> 

回答

0

您還沒有終止邊界和內容係爲 「\ n」

根據MIME規範強制性