为什么不发送已发送邮件的html?

时间:2012-04-04 17:19:44

标签: php html-email

我的脚本发送电子邮件但它不呈现html标记。我不确定为什么不。

$email = $row['email'];

$mail_body = '<html>
<body>

<p>hello,'.$name.'</p>
<p>this is a testing email </p>
<hr />
<p>by server</p>
</body>
</html>';
$subject = "Better website";
$to = "$email";

$headers = "From: mailscript@hotmail.com\r\n";
$headers .= "Content-Type: text/html\r\n";

$mail_result = mail($to, $subject, $mail_body, $headers);

2 个答案:

答案 0 :(得分:2)

尝试设置mime类型以及mail()

手册中显示的内容
// 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";

答案 1 :(得分:0)

正如Jrod已经回答你需要添加标题

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

但是我发现这个问题最近让我搞砸了,不得不发表评论:

$headers  = 'MIME-Version: 1.0' . "\r\n";