php php邮件特殊字符utf8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19708097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:54:20  来源:igfitidea点击:

php mail special characters utf8

phpemailspecial-characters

提问by John Doe Smith

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

主题: 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!

谢谢!

回答by Gregosaurus

Did you try iconv_set_encoding?

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

回答by dead beef

Use &rsquo;in place of the '.

使用&rsquo;到位的”。

Example:

例子:

The dog&rsquo;s bone.

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

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