从php发送邮件 - 字符集编码 [英] send mail from php - charset encoding

查看:160
本文介绍了从php发送邮件 - 字符集编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从php脚本发送一封用希腊语写成的自动邮件。
我试过:

  $ headers =MIME-Version:1.0\r\\\
;
$ headers。=Content-type:text / plain; charset = utf-8\r\\\
;
$ headers。=From:example@mail.com\r\\\
;
$ headers。=回覆:example@mail.com\r\\\
;
mail($ to,$ subject,$ body,$ headers);

身体和主题都是希腊语。 Hotmail正在阅读主题,但不是body和gmail读取的很好。我用iso-8859-7(包含希腊字符)替换了utf-8,它的工作原理。
1)任何想法为什么它不适用于utf-8?
2)还有gmail在邮件中写我的服务器..我如何防止这种情况发生?

解决方案

所有包含主题的电子邮件标题都需要是纯ASCII,您不能直接在电子邮件标题中使用UTF-8或其他编码。一些邮件服务可能能够检测其他编码并做正确的事情,但在技术上无效。使用MIME编码编码您的标头,请参阅如何在使用PHP的邮件功能时使用收件人名称中的特殊字符


I am sending an automated mail,written in Greek, from a php script. I tried:

 $headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "From: example@mail.com\r\n";
$headers .= "Reply-To: example@mail.com\r\n";
mail($to, $subject,$body, $headers) ;

The body and subject are in Greek. Hotmail is reading subject but not the body and gmail reads it well. I replaced utf-8 with iso-8859-7 (contains greek chars) and it works . 1) Any idea why it doesn't work with utf-8? 2) Also gmail is writing my server in the mail.. How can i prevent this from happening?

解决方案

All email headers, which includes the subject, need to be pure ASCII, you cannot use UTF-8 or other encodings directly in email headers. Some mail services may be able to detect other encodings and do the right thing, but it's not technically valid. Encode your headers using MIME encoding, see How to use special characters in recipients name when using PHP's mail function.

这篇关于从php发送邮件 - 字符集编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆