2017-01-06 43 views
0
$to = $emailid; 
$subject = 'APPOINTMENT'; 
$message = "<html> 
<head> 
<title>APPOINTMENT</title> 
</head> 
<body> 
<p>APPOINTMENT</p> 
<table> 
<tr> 
<th>Firstname</th> 
<th>Lastname</th> 
</tr> 
<tr> 
<td>".$fname."</td> 
<td>".$lname."</td> 
</tr> 
</table> 
</body> 
</html> 
"; 

$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html\r\n"; 
$headers = 'From: [email protected]' . "\r\n" . 
'Reply-To: [email protected]' . "\r\n" . 
'X-Mailer: PHP/' . phpversion(); 

if(mail($to,$subject,$message,$headers)) echo "Mail Sent."; 

我发送一个PHP HTML邮件与此code.But问题是,我收到的电子邮件以纯文本(我可以看到HTML标签)。那么问题是什么?据我所知是正确设置的标题。PHP的邮件工作,但让以纯文本格式输出

+0

我认为这不是问题@Progrock的副本 - OP设置内容类型,但是重新设置'$ headers'变量。 – Tom

+0

为什么每个人都坚持以HTML格式发送简单的消息?它增加了大量的数量,复杂性,尤其是安全风险。 – arkascha

+0

@arkascha先生我有一个预约表格,一旦预约表格被提交,就会触发邮件。但是为了测试目的,我只发送两个输入。 –

回答

1

第三次设置时,您正在重置$header变量。以下应该工作;

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
+0

是的,我改变了,但我得到了作为输出的tplain文本。 –

+0

委任

委任

​​KARTHIK ​​克
姓氏

+0

@karthikgm我已经正确重新排序的标题,并增加了字符集值。试试这个。 – Tom

0

替换您的$headers;邮件发送成功在我身边。

$headers .= "Content-Type: text/html\r\n"; 

进入

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

我试过你的代码,但仍然没有获得html格式..我仍然使用纯文本格式。我不知道我错在哪里。 –

+0

它的工作,我得到'HTML'格式的邮件。请检查你的结局。 –

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

我得到的输出now..Thankyou一直以来的支持的