本文实例讲述了php带抄送和密件抄送的邮件发送方法。分享给大家供大家参考。具体分析如下:
程序中用到了php的mail函数,该函数定义如下:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
如果邮件发送成功返回True,否则返回False
<html> <head> <title>Send email with CC and BCC</title> </head> <body> <form action="sendemail.php" method=post name=form1> <table> <tbody> <tr> <td> <div align=right><b>To</b></div></td> <td> <p>Name <input name=mailtoname size=35><br />E-mail <input name=mailtomail size=35></p></td></tr> <tr> <td> <div align=right><b>CC</b></div></td> <td><input name=mailcc size=35> </td></tr> <tr> <td> <div align=right><b>BCC</b></div></td> <td><input name=mailbcc size=35> </td></tr> <tr> <td> <div align=right><b>Priority</b></div></td> <td><select name=mailpriority> <option value=1>Highest</option> <option value=2>High</option> <option selected value=3>Normal</option> <option value=4>Low</option> <option value=5>Lowest</option> </select> </td></tr> <tr> <td><div align=right><b>Subject</b></div></td> <td><input name=mailsubject size=35></td></tr> <tr> <td> <div align=right><b>Message</b> </div></td> <td><textarea cols=50 name=mailbody rows=7></textarea></td></tr> <tr> <td colSpan=2> <div align=center> <input name=Submit type=submit value=Submit></div> </td> </tr> </tbody> </table> </form> </body> </html>
后端php代码,保存为sendmail.php
<html> <head> <title>Send Mail Script</title> </head> <body> <" " ; if (empty ( $mailtoname) || empty ( $mailtomail) ) { die ( "Recipient is blank! ") ; }else{ $to = $mailtoname . " <" . $mailtomail . ">" ; } if ( empty ( $mailsubject) ) { $mailsubject=" "; } if (($mailpriority>0) && ($mailpriority<6)) { $mailheader = "X-Priority: ". $mailpriority ."\n"; } $mailheader.= "From: " . "Sales Team <sales@yourdomain.com>\n"; $mailheader.= "X-Sender: " . "support@yourdomain.com\n"; $mailheader.= "Return-Path: " . "support@yourdomain.com\n"; if (!empty($mailcc)) { $mailheader.= "Cc: " . $mailcc ."\n"; } if (!empty($mailbcc)) { $mailheader.= "Bcc: " . $mailbcc ."\n"; } if (empty($mailbody)) { $mailbody=" "; } $result = mail ($to, $mailsubject, $mailbody, $mailheader); echo "<center><b>Mail sent to ". "$to". "<br />"; echo $mailsubject. "<br />"; echo $mailbody. "<br />"; echo $mailheader. "<br />"; if ($result) { echo "<p><b>Email sent successfully!</b></p>"; }else{ echo "<p><b>Email could not be sent. </b></p>"; } "center"> <table><tr><td width="66"><div align="right"><b>To</b></div></td> <td width="308"><b> <" [". $mailtomail . " ]";"66"><div align="right"><b>CC</b></div></td> <td width="308"><b><"66"><div align="right"><b>BCC</b></div></td> <td width="308"><b><"66"><div align="right"><b>Priority</b></div></td> <td width="308"><b><"66"><div align="right"><b>Subject </b></div></td> <td width="308"><b><"66"><div align="right"><b>Message</b></div></td> <td width="308"><b><?php echo $mailbody;?></b></td></tr> </table> </div> </body> </html>
希望本文所述对大家的php程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月20日
2024年11月20日
- 群星《一人一首成名曲》1998 台湾金碟珍藏版[WAV+CUE][1.1G]
- 陈百强2024-《凝望》头版限量编号MQA-UHQCD[WAV+CUE]
- 测试示范《监听天碟3》头版限量编号LECD[WAV+CUE]
- 陈瑞《爱你到天荒地老HQ》头版限量[低速原抓WAV+CUE]
- 徐小凤 《徐小凤殿堂18首》24K金碟[WAV+CUE]
- 保时捷原厂车载爆棚动态试音碟《Panamera_Soundtrack》DTS[WAV分轨][1G]
- 容祖儿《小小》香港首版 [WAV+CUE][1.1G]
- 莫文蔚《拉活…》SONY [WAV+CUE][1G]
- Beyond《极品天碟》LPCD45II首批限量版[WAV+CUE][1.7G]
- HIFI示范巅峰之作《情解药·Hi-Fi心魂》2CD[WAV+CUE]
- 房东的猫2021-关于彻夜不眠的事情(EP)[青柴文化][WAV+CUE]
- 群星.1993-一曲成名·青春无悔【飞碟】【WAV+CUE】
- 张芸京.2016-失败的高歌【泡耳音乐】【WAV+CUE】
- 天籁女声《2024第31届上海国际高端音影展纪念CD》[WAV+CUE][1.1G]
- 姚斯婷 《敢爱敢做》头版限量编号24K金碟[低速原抓WAV+CUE][1.2G]