[英]PHP mail not rendering spanish accent correctly
Currently when sending an email from PHP which includes a spanish accent, the email is being rendered as follow: 目前,当从PHP发送包含西班牙口音的电子邮件时,电子邮件呈现如下:
Ω₯ζλZΫiz«’Ό*'΅ινO*^rνz{
I'm setting the following headers: 我正在设置以下标题:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
A sample body message is: 示例正文消息是:
Estudio bíblico en Web Church Connect
I'm also setting the charset of the html: 我也设置了html的charset:
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>WebChurchConnect</title>
</head>
<body>
';
Any thoughts is appreciated. 任何想法都表示赞赏。
Thanks. 谢谢。
E-Mail only accepts ASCII characters as many MTAs are not equipped to correctly relay other messages. 电子邮件只接受ASCII字符,因为许多MTA没有配备正确中继其他消息。 You should think of MIME-E-Mails like onions: (they smell, they make you cry) and they have layers . 您应该将MIME-E-Mails视为洋葱:(它们闻起来,它们会让你哭泣)并且它们有层次 。 The HTML message (inner layer) only gets decoded after the plain text of your message is handled (outer layer). HTML消息(内层)仅在处理完消息的纯文本(外层)后才会被解码。
You need to explicitly encode any non-ASCII characters in the “outer” layer. 您需要在“外部”层中显式编码任何非ASCII字符。 You do this using the Content-Transfer-Encoding
header, which can be set to either base64
or quoted-printable
(some modern MTAs also support 8bit
or binary
but these must be set explicitly and support still isn't as universal as one would hope for in 2014). 您可以使用Content-Transfer-Encoding
标头执行此操作,该标头可以设置为base64
或quoted-printable
(某些现代MTA也支持8bit
或binary
但这些必须明确设置,支持仍然不像人们希望的那样普遍在2014年)。 Of course the MIME part that follows this header also needs to be actually encoded using the method specified. 当然,此标头后面的MIME部分也需要使用指定的方法进行实际编码。 Fortunately Base64-Encoding is only a base64_encode
call away. 幸运的是,Base64-Encoding只是一个base64_encode
调用。
Alternatively, since your message is in HTML (and you don't seem to care about providing a plaintext alternative – which you should), you could also use HTML's escaping mechanisms (eg í
instead of í
), but Base64 is generally safer since it's immune to the MTAs that take it upon themselves to break up long lines after 78 characters. 或者,由于您的消息是HTML格式(并且您似乎并不关心提供明文替代方案 - 您应该这样做),您也可以使用HTML的转义机制(例如í
而不是í
),但Base64通常更安全它可以免受MTA的攻击,这些MTA可以在78个字符之后分解长线。
Try using PHPMailer or SwiftMailer . 尝试使用PHPMailer或SwiftMailer 。 Problems like these are there already solved, everything is tested and its much easier for you to work with. 像这样的问题已经解决了,所有的东西都经过测试,并且它更容易让你使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.