2010-07-07 29 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);