Home  >  Article  >  Backend Development  >  Introduction to the solution to garbled characters in PHP function mail()_PHP Tutorial

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

WBOY
WBOYOriginal
2016-07-15 13:30:04782browse

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>

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...
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