【问题标题】:PHP mail() changing some characters to htmlentities?PHP mail() 将某些字符更改为 htmlentities?
【发布时间】:2015-01-25 17:44:42
【问题描述】:

! 位于电子邮件正文的标记中时,我的PHP mail() 脚本将某些电子邮件客户端(例如hotmail)上的! 感叹号更改为%21

这是我的脚本

$to = "myemail@outlook.com";
$subject = "Password Reset";
$body = "<a href=\"http://example.com/#!/page\">Link 1</a>
        <br><br>
        Without href: http://example.com/#!/page - regular text
    ";
$headers = "From: no-reply@example.com\r\n";
$headers .= "Reply-To: no-reply@example.com\r\n";
$headers .= "Return-Path: no-reply@example.com\r\n";
$headers .= "X-Mailer: PHP5\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
mail($to,$subject,$body,$headers);

所以在上面的脚本中,! 只有在它是链接时才更改为%21,常规文本将其保持为/#!/,而不是将其转换为/#%21/

我将如何解决此问题,使其不会更改为 %21

【问题讨论】:

    标签: php email html-email html-entities html-encode


    【解决方案1】:

    某些字符被编码是因为它们不是有效的 URL。在您的情况下,URL code points 被替换为百分比编码字节 %

    【讨论】:

    • 那我该怎么解决这个问题?
    • 这不是问题。它只是逃脱了。
    • 好的,那我怎么让它不逃跑呢?我需要href 有#! 而不是#%21
    • 这取决于您如何阅读它。如果你解析 dom,你不需要做任何特别的事情。但是您可以对该文本进行 urldecode 以将其转换回来。请注意,属性中的 url 需要正确编码才能成为正确的 html。 php.net/manual/en/function.urldecode.php
    猜你喜欢
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 2012-02-13
    相关资源
    最近更新 更多