收藏本页 | 网站地图 | 投稿指南
 
 
当前位置:首页 >> 学院首页 >> 程序开发 >> PHP >>

PHP使用mail函数发送邮件标题乱码问题

放大字体  缩小字体  At: 2007-09-18 20:13  By: master8 转载 来源: 互联网

PHP程序使用mail()函数发送邮件的时候,标题中文的话会出现乱码。

解决方法:
先用函数base64_encode() ― 使用 MIME base64 对数据进行编码
标题字符串前加编码类型例如: =?UTF-8?B?
标题字符串后加:?=
邮件header说明Content-type ― 防止邮件正文也乱码

举例:

  1. $to         = 'xinple@example.com';
  2. $subject  = "=?UTF-8?B?".base64_encode('邮件标题')."?=";
  3. $headers  = 'MIME-Version: 1.0' . "\r\n";
  4. $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
  5. // Additional headers
  6. $headers .= 'To: Xinple <xinple@example.com>' . "\r\n";
  7. $headers .= 'From: Admin <admin@example.com>' . "\r\n";
  8. $headers .= 'Reply-To: Xinple <xinple@example>' . "\r\n";
  9. mail($to, $subject, $message, $headers);






         









 
Google
论坛精华  
 
-->
 
  ©2005-2008 站长吧 Master8.NET All Rights Reserved 陕ICP备05010609号