PHP Mail函数在收件箱中将消息显示为纯文本

时间:2010-07-07 07:33:49

标签: php email

我尝试从我的php应用程序发送邮件。邮件发送成功但纯文本邮件包含html tags.is有任何解决方案。请帮助我。我的消息如下

 $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 个答案:

答案 0 :(得分: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 :(得分:0)

您必须设置:Content-type:text / html;在邮件的标题中。

答案 2 :(得分:0)

$ headers ='MIME-Version:1.0'。为 “\ r \ n” 个; $ headers。='Content-type:text / html; charset = iso-8859-1'。为 “\ r \ n” 个; 邮件($到,$主题,$消息,$头);