首页 > php框架 > PHP函数mail()的乱码解决方法介绍

PHP函数mail()的乱码解决方法介绍

一些人在使用PHP进行编程操作时,经常会遇到一些问题。比如在使用
PHP函数mail()出现乱码的解决方法:

先用函数base64_encode() — 使用 MIME base64 对数据进行编码

标题字符串前加编码类型例如: =?UTF-8?B?

标题字符串后加:?=

邮件header说明Content-type — 防止邮件正文也乱码 举例说明:

  1. $to         = ‘name@example.com’;  
  2.  
  3. $subject  = “=?UTF-8?B?”.base64_encode(’邮件标题’).”?=”;  
  4.  
  5. $headers  = ‘MIME-Version: 1.0′ . “rn”;  
  6.  
  7. $headers .= ‘Content-type: text/html; charset=utf-8′ . “rn”;  
  8.  
  9. // Additional headers  
  10.  
  11. $headers .= ‘To: Name < name@example.com>’ . “rn”;  
  12.  
  13. $headers .= ‘From: Admin < admin@example.com>’ . “rn”;  
  14.  
  15. $headers .= ‘Reply-To: Name < name@example.com>’ . “rn”;  
  16.  
  17. mail($to, $subject, $message, $headers);  
  18.  

以上就是PHP函数mail()在使用时出现乱码的具体解决方法。


教程网址:http://www.phprm.com/frame/php1003659.html

欢迎收藏∩_∩但请保留本文链接。

标签:none

发表留言