2010-07-07 25 views
0

我嘗試從我的php應用程序發送郵件。郵件發送成功,但包含html tags的純文本電子郵件。有任何解決方案。請幫助我。我的消息如下所示:PHP郵件功能在收件箱中將郵件顯示爲純文本

$message = ' 
       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
        <html xmlns="http://www.w3.org/1999/xhtml"> 
         <head> 
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
           <title>Gaishan</title> 
         </head> 
         <body> 
          <table width="750" border="0" cellspacing="0" cellpadding="0" style="background-color:#043c58; padding:15px;"> 
          <tr> 
           <td style="padding-bottom:10px;"><a href="#"><img src="http://www.toobler.com/staging/gaishan/index.php/users/ec/1/logo_mail.jpg"; border="0" /></a></td> 
          </tr> 
          <tr> 
           <td colspan="2" style="background-color:#fff; padding:10px 30px;"><h1 style="font-family:Arial, Helvetica, sans-serif; font-size:26px; font-weight:bold; color:#111;">testmail</h1> 
            <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#555; line-height:22px;">http://www.toobler.com/</p> 
             <a href="http://www.toobler.com/" style="font-family:Arial, Helvetica, sans-serif; color:#7ea515; text-decoration:underline;">http://www.toobler.com/staging/gaishan/index.php/users/ec/1/'.time().'</a> 
             <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo textDemo text</p> 
             <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo textDemo textDemo text</p> 
             <br /> 
             <p style="font-family:Arial, Helvetica, sans-serif; font-size:14px; font-weight:normal; color:#4a483f; line-height:22px;">Demo textDemo textDemo text<br /> 
             Demo textDemo textDemo text Demo textDemo text 
             </p> 
           </td> 
          </tr> 
         </table> 
        </body> 
       </html> 
       '; 

回答

3

您是否還設置標題來表明電子郵件應該是HTML?如果你不這樣做,它將永遠只是純文本。

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

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

同意,但是編碼(字符集)應該是utf-8,因爲這是包含在html中的一個,我belileve。 – 2010-07-07 07:46:05

+0

非常感謝。完美的工作 – abhis 2010-07-07 07:49:15

+0

斑點莫里茨+1 – 2010-07-07 09:01:14

0

您必須設置:Content-type:text/html;在郵件的標題中。

0

$ headers ='MIME-Version:1.0'。爲 「\ r \ n」 個; $ headers。='Content-type:text/html; charset = iso-8859-1'。爲 「\ r \ n」 個; 郵件($ to,$ subject,$ message,$ headers);