2016-01-22 102 views
0

我已经在本地主机中设置了电子邮件发送,并使用它可以访问我的gmail帐户以使用php脚本发送邮件。未在邮件中显示HTML内容

<?php 

$to = "[email protected]"; 
$subject = "HTML Mail"; 
$message = "<html><body>"; 
$message .= "<b>Hey! How are you today?</b>"; 
$message .= "<br>Regards"; 
$message .= "</body></html>"; 

$headers = "From: [email protected]\r\n"; 


mail($to,$subject,$message,$headers); 
echo "<h1>MAIL SENT</h1>"; 
?> 

当我把使用这个脚本了该邮件,它给出了

<html><body><b>Hey! How are you today?</b><br>Regards</body></html> 

为什么不显示HTML类型的输出?

嘿!你今天好吗?
Regards

像这样在Gmail吗?

回答

1

从邮件()的PHP文件:

// 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

是它的工作:d –

2

难道是你缺少标题来指定这是HTML内容?

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 

编辑:正如另一个答案所指出的,两个标题都是必需的。

1

嗨发送电子邮件与HTML正文您需要指定标题。事情是这样的

//your code <br> 
$headers = "From: [email protected]\r\n"; <br> 
//HTML headers <br> 
$headers .= 'MIME-Version: 1.0' . "\r\n"; <br> 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

所以以后你可以用HTML身体

mail($to,$subject,$message,$headers); 

好运发送电子邮件