2012-04-04 165 views
1

我的脚本发送电子邮件,但它不呈现html标记。我不确定为什么不。为什么不发送发送的邮件的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: [email protected]\r\n"; 
$headers .= "Content-Type: text/html\r\n"; 

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

回答

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"; 
+0

我想补充的另一件事是,从未使用aol,hotmail,yahoo,gmail或其他任何知名的邮件头,因为godaddy邮件服务器拒绝他们。 – engma 2012-11-03 16:18:16

0

为Jrod已经回答了你需要添加页眉

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

,但我发现,这一个是最近搞砸了,不得不将它评论出来:

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