PHP函数mail()的乱码解决方法介绍
一些人在使用PHP进行编程操作时,经常会遇到一些问题。比如在使用
PHP函数mail()出现乱码的解决方法:
先用函数base64_encode() — 使用 MIME base64 对数据进行编码
标题字符串前加编码类型例如: =?UTF-8?B?
标题字符串后加:?=
邮件header说明Content-type — 防止邮件正文也乱码 举例说明:
- $to = ‘name@example.com’;
- $subject = “=?UTF-8?B?”.base64_encode(’邮件标题’).”?=”;
- $headers = ‘MIME-Version: 1.0′ . “rn”;
- $headers .= ‘Content-type: text/html; charset=utf-8′ . “rn”;
- // Additional headers
- $headers .= ‘To: Name < name@example.com>’ . “rn”;
- $headers .= ‘From: Admin < admin@example.com>’ . “rn”;
- $headers .= ‘Reply-To: Name < name@example.com>’ . “rn”;
- mail($to, $subject, $message, $headers);
以上就是PHP函数mail()在使用时出现乱码的具体解决方法。
教程网址:http://www.phprm.com/frame/php1003659.html
欢迎收藏∩_∩但请保留本文链接。