php邮件特殊字符utf8

Joh*_*ith 4 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\nContent-Transfer-Encoding: 8bit\n");
?>
Run Code Online (Sandbox Code Playgroud)

在电子邮件中:

学科: Testmail ? Special Characters

身体:

Hi there,

this isn?t something easy.

I haven?t thought that it?s that complicated!
Run Code Online (Sandbox Code Playgroud)

我尝试了很多东西,但我已经没有想法了.你能帮助我吗?你有没有这个工作?

谢谢!

Gre*_*rus 12

你尝试过iconv_set_encoding吗?

这应该工作:

<?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");?>
Run Code Online (Sandbox Code Playgroud)

  • 哇,它适用于正文,但不适用于主题:“Testmail Special Characters”想法? (2认同)
  • 使用 [mb_encode_mimeheader](http://php.net/manual/en/function.mb-encode-mimeheader.php) 作为主题: $subject = mb_encode_mimeheader($subject,"UTF-8"); (2认同)