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