首页 > php教程 > php手册 > 正文

一个发送HTML邮件的PHP函数

WBOY
发布: 2016-06-13 10:38:02
原创
1746 人浏览过

  写了一个简单的发送HTML邮件的PHP函数。

  函数说明:send_mail("发件人地址", "收件人地址", "邮件主题", "邮件正文");

  示例:

<ol class="dp-xml"><li class="alt"><span><span>send_mail($from, lvtao@php100.net, "这是邮件的主题", "</span><span class="tag"><span class="tag-name">html</span><span class="tag">></span><span class="tag"><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 class="tag-name">body</span><span class="tag">></span><span class="tag"><span class="tag-name">p</span><span class="tag">></span><span class="tag"><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></span></span></span></span></span></li></ol><br><br>  代码如下:
登录后复制
<ol class="dp-c">
<li class="alt"><span><span><?php      </span></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></lvtao></span><span>;</span><span class="comment">//发件人地址    </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>
登录后复制

 

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板