dongle3217 2011-10-24 18:01
浏览 31

从php发送邮件 - charset编码

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

 $headers  = "MIME-Version: 1.0
";
$headers .= "Content-type: text/plain; charset=utf-8
";
$headers .= "From: example@mail.com
";
$headers .= "Reply-To: example@mail.com
";
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?

  • 写回答

1条回答 默认 最新

  • duanjia2772 2011-10-25 01:34
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分