如何避免在邮件功能中显示HTML标签 [英] How to avoid display of HTML tags in mail function

查看:104
本文介绍了如何避免在邮件功能中显示HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个邮件功能,并且可以正常工作,我收到邮件.但是问题是我也照原样获得了HTML标签.我的代码如下:

I have a mail function, and it works fine, I get mails. But the problem is that I also get the HTML tags as it is. I have code as follows:

$from=$_REQUEST['id'];  
$to  = 'xyz@abc.com';  

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

$headers = "From: $from \r\n" .  
    "Reply-To: $from \r\n" .  
    "X-Mailer: PHP/" . phpversion();  

$subject="Contact Mail has received";  

$message=" SOME HTML TAGS ";

在邮件正文中,我有HTML标签,例如 table tr td 等.但是,当我收到邮件时,我不要拿桌子.我将所有HTML标记分别作为 table tr td .在标题中,我甚至将内容类型指定为 text/html ,但仍然存在相同的问题.

Inside the message body, I have HTML tags like table, tr, td, etc. But when I receive the mail, I don't get the table. I get all the HTML tags as table, tr, td. In header, I have even specified content type as text/html, but still I have the same issue.

如何避免这种情况?

推荐答案

您没有指定 text/html ,因为您覆盖了标题!

You haven't specified text/html because you are overwritting you headers!

在这里,您先分配它,然后将其覆盖:

Here, you assign it then overwrite it:

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

$headers = "From: $from \r\n" .  
       "Reply-To: $from \r\n" .  
       "X-Mailer: PHP/" . phpversion();  

应该是

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

$headers .= "From: $from \r\n" .  
       "Reply-To: $from \r\n" .  
       "X-Mailer: PHP/" . phpversion();  

您错过了一个附加更多标题的圆点.这会覆盖您的Content-Type,这就是为什么它将电子邮件解析为文本并且没有HTML

You missed a dot to append more headers. This overwrites your Content-Type and that is why it is parsing the email as text and not has HTML

这篇关于如何避免在邮件功能中显示HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆