Php电子邮件,只发送与主题字符在Outlook中的问题 [英] Php email sent with issues on subject chars in Outlook only
问题描述
我使用php发送邮件,邮件的主题有口音。
Im sending a mail using php, and the subject of the mail has accents.
我在Outlook中接收奇怪的字符,而不是重音字符。如果我在网络电子邮件客户端看到电子邮件,我看到主题完美。
Im receiving weird characters in Outlook instead the accented chars. If i see the email in a web email client i see the subject perfect.
这是我用来发送电子邮件的代码:
This is the code that im using to send the email:
$to = 'whateveremail@whatever.com';
$subject = '[WEBSITE] áccent – tésts';
$message = '<p>Test message</p>
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers.= 'From:equipothermomix@thermomix.com' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message , $headers);
我如何解决问题,我必须使用另一个字符集吗?
How i could solve the issue, do i have to use another charset?
推荐答案
发送电子邮件的唯一可靠的方法是使用纯7位ASCII,所以你需要正确编码字符串,当你想使用任何其他。在你的情况下, [WEBSITE]áccent - tésts
应编码为(eg) =?windows-1252?B?W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz?=
,其中字符串拆分为:
The only reliable way to send e-mail is using plain 7 bit ASCII so you need to encode strings properly when you want to use anything else. In your case, [WEBSITE] áccent – tésts
should be encoded as (e.g.) =?windows-1252?B?W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz?=
, where the string splits as:
=?windows-1252?B?W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz?=
^ ^ ^
| | |
Charset | Data
|
Base64
检查:
echo base64_decode('W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz'); // [WEBSITE] áccent – tésts
这只是一个可能的编码方式的例子非ASCII字符串。
This is just an example of one of the possible ways to encode non-ASCII strings.
发送电子邮件时,有很多细节需要注意。这就是为什么迟早你最好使用一个合适的电子邮件包,如 Swift Mailer 或 PHPMailer 。
When sending e-mail, there are many little details like this that need attention. That's why sooner or later you end up using a proper e-mail package like Swift Mailer or PHPMailer.
这篇关于Php电子邮件,只发送与主题字符在Outlook中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!