Introduction to the solution to garbled characters in PHP function mail()_PHP Tutorial

WBOY
Release: 2016-07-15 13:30:04
Original
831 people have browsed it

Some people often encounter some problems when using PHP for programming operations. For example, when using the PHP function mail(), the solution appears:

First use the function base64_encode() - use MIME base64 to encode the data Encode

Add the encoding type before the header string. For example: =?UTF-8?B?

Add after the header string: ?=

Email header description Content- type - To prevent the email body from being garbled. Example:

<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><span class="tag-name">name</span><span>@example.com</span><span class="tag">></span><span>’ . “rn”;  </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><span class="tag-name">admin</span><span>@example.com</span><span class="tag">></span><span>’ . “rn”;  </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><span class="tag-name">name</span><span>@example.com</span><span class="tag">></span><span>’ . “rn”;  </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

The above is the specific solution to the garbled code when using the PHP function mail().


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446310.htmlTechArticleSome people often encounter some problems when using PHP for programming operations. For example, the solution to garbled characters when using the PHP function mail(): First use the function base64_encode() and use MIME ba...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template