php mail special characters utf8

﹥>﹥吖頭↗ 提交于 2019-11-26 08:30:51

问题


I have the following script:

<?php
    $subject = \"Testmail — Special Characters\";
    $msg = \"Hi there,\\n\\nthis isn’t something easy.\\n\\nI haven’t thought that it’s that complicated!\";

    mail($to,$subject,$msg,$from.\"\\nContent-Type: text/plain; charset=UTF-8\\nContent-Transfer-Encoding: 8bit\\n\");
?>

In the e-mail:

Subject: Testmail ? Special Characters

Body:

Hi there,

this isn?t something easy.

I haven?t thought that it?s that complicated!

I tried a lot of things, but I have no ideas anymore. Can you help me? Did you ever got this working?

THX!


回答1:


Did you try iconv_set_encoding ?

This should work :

<?php
 iconv_set_encoding("internal_encoding", "UTF-8");

$subject = "Testmail — Special Characters";
$msg = "Hi there,\n\nthis isn’t something easy.\n\nI haven’t thought that it’s that complicated!";

mail(utf8_decode($to), utf8_decode($subject), utf8_decode($msg), utf8_decode($from)."\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n");?>



回答2:


Use &rsquo; in place of the ’.

Example:

The dog&rsquo;s bone.

Make sure you change the content-type from text/plain to text/html.



来源:https://stackoverflow.com/questions/19708097/php-mail-special-characters-utf8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!