消息复制中的 PHP 发送标头

  • 本文关键字:PHP 复制 消息 php email
  • 更新时间 :
  • 英文 :


我正在尝试使用PHP发送和HTML格式的电子邮件。我一直在进行故障排除,但这是我的测试代码:

$email ="
<html> 
  <body> 
    <p style="text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;">
        <b>I am receiving HTML email</b>
        <br/><br/><br/><a style="text-decoration:none;color:#246;" href="www.example.com">example</a>
    </p>
    <br/><br/>Now you Can send HTML Email
  </body>
</html>";

$emailaddress = "personsemail@website.com";
$subject = "Test Email";
$headers = "From: noreply@server.comrn";
$headers .= "Content-type: text/htmlrn";

mail($emailaddress, $subject, $email, $headers);

FROM 标题有效,但电子邮件不显示为 HTML,相反,我得到的纯文本如下所示:

Content-type: text/html
Message-Id: <randomnumber@servername.hostingprovidor.com>
Date: Tue, 28 Apr 2015 12:45:48 -0500 (EST)

<html>
  <body>
    <p style="text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;">
        <b>I am receiving HTML email</b>
        <br/><br/><br/><a style="text-decoration:none;color:#246;" href="www.example.com">example</a>
    </p>
    <br/><br/>Now you Can send HTML Email
  </body>
</html>

这是服务器设置问题吗?感谢您的帮助。

为了将电子邮件内容显示为html,您需要更多标题,请尝试以下操作:

$email = <<< LOL
<html> 
  <body> 
    <p style="text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;">
        <b>I am receiving HTML email</b>
        <br/><br/><br/><a style="text-decoration:none;color:#246;" href="www.example.com">example</a>
    </p>
    <br/><br/>Now you Can send HTML Email
  </body>
</html>
LOL;
$emailaddress = "personsemail@website.com";
$subject = "Test Email";
$headers = "From: noreply@server.comrn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=ISO-8859-1rn";

mail($emailaddress, $subject, $email, $headers);

您可能应该在标头中设置 MIME 类型。 试试这个:

$headers = 'From: noreply@server.com' . "rn";
$headers .= 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";

最新更新