search
Homephp教程php手册PHP函数mail()的乱码解决方法介绍

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

Jun 13, 2016 am 11:07 AM
mailphpGarbled charactersintroduceusefunctionexistoperatemethodhourofprogrammingsolveconductmeet

一些人在使用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>

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


Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor