Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php邮件特殊字符utf8_Php_Email_Special Characters - Fatal编程技术网

php邮件特殊字符utf8

php邮件特殊字符utf8,php,email,special-characters,Php,Email,Special Characters,我有以下脚本: <?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\nCont

我有以下脚本:

<?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");
?>
我尝试了很多东西,但我再也没有主意了。 你能帮助我吗?你做过这个吗

谢谢

你试过了吗

这应该起作用:

<?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");?>

使用
代替了“”的位置

例如:

The dog&rsquo;s bone.

确保将内容类型从text/plain更改为text/html。

wow,它对正文很有效,但对主题“Testmail”无效� 特殊字符“Ideas?”@johndesmith:原因是您无法utf8_decode()解码没有等效1字节表示形式的字符,例如长破折号。我不明白你怎么能接受这个主题的答案:$subject=mb_encode_mimeheader($subject,“UTF-8”);添加正确的邮件标题,而不是尝试将内容解码回较弱的编码,这样会更好(阅读:对我来说更好)。更干净的代码,更少的bug。那太容易了。如果这样做,我将得到准确的;在输出/电子邮件中
The dog&rsquo;s bone.