【问题标题】:PHP mail() can't find a solution for accents in message contentPHP mail() 找不到消息内容中重音的解决方案
【发布时间】:2018-11-10 19:20:48
【问题描述】:

我已经尝试了很多关于它的解决方案,但仍然找不到有效的解决方案。电子邮件已成功发送,但重音在 html 代码中。

这是我的电子邮件内容代码:

        $to_APPLICATION_RECEIVER = "w@z.ca";
        $from_APPLICATION_RECEIVER = "x@y.com";
        $subject_APPLICATION_RECEIVER = "Subject";
        $headers_APPLICATION_RECEIVER = 'From: "people" <x@y.com> \r\n';
        $headers_APPLICATION_RECEIVER .= 'Reply-to: x@y.com \r\n';

        //define boundary
        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

        //tell header about $mime_boundary
        $headers_APPLICATION_RECEIVER .= "\nMIME-Version: 1.0\n";
        $headers_APPLICATION_RECEIVER .= "Content-Type: multipart/mixed;\n";
        $headers_APPLICATION_RECEIVER .= " boundary=\"{$mime_boundary}\"";

        //Message section
        //$message = utf8_decode($message);
        $message_hed_APPLICATION_RECEIVER ="\n\n--{$mime_boundary}\n";
        $message_hed_APPLICATION_RECEIVER .="Content-Type: text/plain; charset=\"UTF-8\"\n";
        $message_hed_APPLICATION_RECEIVER .="Content-Transfer-Encoding: 8bit\n\n" . $message . "\n\n";
        $message_hed_APPLICATION_RECEIVER .= "--{$mime_boundary}\n";

var_dump 显示的$message 的内容是"sfdféèî",但我收到的邮件内容是:sfdf&amp;eacute;&amp;egrave;&amp;icirc;。有人可以帮我吗?我在论坛上尝试了utf8_decode() 和许多其他提议,但仍然没有用。谢谢你们的帮助。

【问题讨论】:

标签: php email mime


【解决方案1】:

如果您查看页面的source,您将看到您的字符串实际上确实 包含html 实体。 var_dump() 会像这样暗示这种情况:

string(27) "sfdféèî"

您可以使用以下方法将实体转换回 UTF8:

html_entity_decode('sfdf&eacute;&egrave;&icirc;')

产量:

string(10) "sfdféèî"

【讨论】:

  • 出于安全考虑我使用了htmlentities(),使用html_entity_decode()不会取消htmlentities()的效果吗?
  • “安全目的”,但您似乎不明白这些目的是什么。您可能应该阅读更多内容,并重新评估您的“安全”决定。在这个特定的上下文中,只要您不决定在某个时候将电子邮件的内容类型更改为 html,就可以了。
  • 那么,无论您用来查看该数据的什么,都不会将其解释为 UTF-8。 stackoverflow.com/questions/279170/utf-8-all-the-way-through
猜你喜欢
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
  • 1970-01-01
  • 1970-01-01
  • 2015-05-06
  • 1970-01-01
相关资源
最近更新 更多