Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 11:07:22
Original
1008 people have browsed it

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

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

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

标题字符串后加:?=

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

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute">to</span><span>         = ‘name@example.com’;  </span></span></li>
<li><span> </span></li>
<li class="alt">
<span>$</span><span class="attribute">subject</span><span>  = “=?UTF-8?B?”.base64_encode(’邮件标题’).”?=”;  </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>$</span><span class="attribute">headers</span><span>  = ‘MIME-Version: 1.0′ . “rn”;  </span>
</li>
<li><span> </span></li>
<li class="alt">
<span>$headers </span><span class="attribute">.</span><span>= ‘Content-type: text/html; </span><span class="attribute">charset</span><span>=</span><span class="attribute-value">utf</span><span>-8′ . “rn”;  </span>
</li>
<li><span> </span></li>
<li class="alt"><span>// Additional headers  </span></li>
<li><span> </span></li>
<li class="alt">
<span>$headers </span><span class="attribute">.</span><span>= ‘To: Name </span><span class="tag"><span> </span><span class="tag-name">name</span><span>@example.com</span><span class="tag">></span><span>’ . “rn”;  </span></span>
</li>
<li><span> </span></li>
<li class="alt">
<span>$headers </span><span class="attribute">.</span><span>= ‘From: Admin </span><span class="tag"><span> </span><span class="tag-name">admin</span><span>@example.com</span><span class="tag">></span><span>’ . “rn”;  </span></span>
</li>
<li><span> </span></li>
<li class="alt">
<span>$headers </span><span class="attribute">.</span><span>= ‘Reply-To: Name </span><span class="tag"><span> </span><span class="tag-name">name</span><span>@example.com</span><span class="tag">></span><span>’ . “rn”;  </span></span>
</li>
<li><span> </span></li>
<li class="alt"><span>mail($to, $subject, $message, $headers);  </span></li>
<li><span> </span></li>
</ol>
Copy after login

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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!