[英]PHP mail utf-8 issues
I've trying to send an email in utf-8
encoding using a PHP mail() func. 我试图使用PHP mail()函数以
utf-8
编码发送电子邮件。 And there's some issues with this. 这有一些问题。 Such as:
如:
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
. Content-Type: text/plain; charset=us-ascii
。 This behavior is not depending of sending a header Content-Type: text/plain; charset=UTF-8
Content-Type: text/plain; charset=UTF-8
Content-Type: text/plain; charset=UTF-8
utf-8
chars that encoded according to RFC2047 then I receive a double encoded subject like this Subject: =?us-ascii?Q?=3D=3FUTF-8=3FB=3Fw5HClsORwpfDkcKU=3F=3D?=
. utf-8
字符组成,那么我会收到一个类似此Subject: =?us-ascii?Q?=3D=3FUTF-8=3FB=3Fw5HClsORwpfDkcKU=3F=3D?=
的双编码Subject: =?us-ascii?Q?=3D=3FUTF-8=3FB=3Fw5HClsORwpfDkcKU=3F=3D?=
。 Instead of expected Subject: =?UTF-8?B?w5HClsORwpfDkcKU?=
Subject: =?UTF-8?B?w5HClsORwpfDkcKU?=
Example: 例:
$subject = 'іїє';
$body = 'іїє';
$headers = "Content-Type: text/plain; charset=UTF-8\r\n"
. "MIME-Version: 1.0\r\n";
mail('some-address@gmail.com', mb_encode_mimeheader($subject, 'UTF-8', 'B'), $body, $headers);
Here is the part of received headers: 这是收到的标头的一部分:
Subject: =?us-ascii?Q?=3D=3FUTF-8=3FB=3Fw5HClsORwpfDkcKU=3F=3D?=
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: application/octet-stream
Content-Transfer-Encoding: 8bit
С–С—С”
As MTA on server is installed postfix. 由于服务器上的MTA已安装后缀。 As a client using gmail
作为使用gmail的客户端
Email is a very archaic, outdated, and difficult technology. 电子邮件是一种非常古老,过时且困难的技术。 This is especially true with character encoding.
对于字符编码尤其如此。 I would suggest using a library, such as PHPMailer .
我建议使用库,例如PHPMailer 。 If you insist upon doing this from scratch, the true answer will go beyond the scope of your question.
如果您坚持从头开始,那么真正的答案将超出您的问题范围。 Browsers, clients, and much more complicate this issue.
浏览器,客户端等使此问题复杂化。 I can't tell you the cause of your issue, but the solution is PHPMailer.
我无法告诉您问题的原因,但是解决方案是PHPMailer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.