Home > Backend Development > PHP Tutorial > A PHP function to send HTML emails_PHP tutorial

A PHP function to send HTML emails_PHP tutorial

WBOY
Release: 2016-07-13 17:39:13
Original
826 people have browsed it

Written a simple PHP function for sending HTML emails.

Function description: send_mail("Sender address", "Recipient address", "Email subject", "Email text");

Example:

<ol class="dp-xml"><li class="alt"><span><span>send_mail($from, lvtao@php100.net, "这是邮件的主题", "</span><span class="tag"><</span><span class="tag-name">html</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">head</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">head</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">body</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">p</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">font</span><span> </span><span class="attribute">color</span><span>=</span><span class="attribute-value">red</span><span class="tag">></span><span>这是邮件正文</span><span class="tag"></</span><span class="tag-name">font</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">p</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">body</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">html</span><span class="tag">></span><span>"); </span></span></li></ol><br><br>  代码如下:
Copy after login
<ol class="dp-c">
<li class="alt"><span><span><?php     </span></span></li><li><span class="keyword">function</span><span> send_mail(</span><span class="vars">$from</span><span>, </span><span class="vars">$to</span><span>, </span><span class="vars">$subject</span><span>, </span><span class="vars">$message</span><span>)     </span></li><li class="alt"><span>{     </span></li><li><span>    </span><span class="keyword">if</span><span> (</span><span class="vars">$from</span><span> == </span><span class="string">""</span><span>)     </span></li><li class="alt"><span>    {     </span></li><li><span>        </span><span class="vars">$from</span><span> = </span><span class="string">吕滔 <lvtao@php100.net></span><span>;</span><span class="comment">//发件人地址    </span><span> </span></span></li>
<li class="alt"><span>    }     </span></li>
<li>
<span>    </span><span class="vars">$headers</span><span> = </span><span class="string">MIME-Version: 1.0</span><span> . </span><span class="string">"
"</span><span>;     </span>
</li>
<li class="alt">
<span>    </span><span class="vars">$headers</span><span> .= </span><span class="string">Content-type: text/html; charset=gb2312</span><span> . </span><span class="string">"
"</span><span>;     </span>
</li>
<li>
<span>    </span><span class="vars">$headers</span><span> .= </span><span class="string">From: </span><span> . </span><span class="vars">$from</span><span> . </span><span class="string">"
"</span><span>;     </span>
</li>
<li class="alt">
<span>    mail(</span><span class="vars">$to</span><span>, </span><span class="vars">$subject</span><span>, </span><span class="vars">$message</span><span>, </span><span class="vars">$headers</span><span>);     </span>
</li>
<li><span>}     </span></li>
<li class="alt"><span>?>   </span></li>
</ol>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486324.htmlTechArticleWritten a simple PHP function for sending HTML emails. Function description: send_mail(sender address, recipient address, email subject, email body); Example: send_mail($from,lvtao@php100....
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