【问题标题】:How to avoid display of HTML tags in mail function如何避免在邮件功能中显示 HTML 标签
【发布时间】:2011-03-29 10:10:51
【问题描述】:

我有一个邮件功能,它工作正常,我收到邮件。但问题是我也得到了 HTML 标签。我的代码如下:

$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 ";

在邮件正文中,我有 tabletrtd 等 HTML 标签。但是当我收到邮件时,我没有得到表格。我得到所有的 HTML 标签为tabletrtd。在标题中,我什至将内容类型指定为text/html,但我仍然遇到同样的问题。

我怎样才能避免这种情况?

【问题讨论】:

标签: php html


【解决方案1】:

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

在这里,你分配它然后覆盖它:

$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

【讨论】:

    猜你喜欢
    • 2012-11-28
    • 1970-01-01
    • 2020-02-20
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 2018-10-29
    相关资源
    最近更新 更多