php带抄送和密件抄送的邮件发送方法
网络编程 2021-07-05 09:09www.168986.cn编程入门
这篇文章主要介绍了php带抄送和密件抄送的邮件发送方法,涉及php中mail函数的使用技巧,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了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=mail size=35> </td></tr> <tr> <td> <div align=right><b>BCC</b></div></td> <td><input name=mailb 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> <?php $message= " " ; 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.>\n"; $mailheader.= "X-Sender: " . "support@yourdomain.\n"; $mailheader.= "Return-Path: " . "support@yourdomain.\n"; if (!empty($mail)) { $mailheader.= "Cc: " . $mail ."\n"; } if (!empty($mailb)) { $mailheader.= "B: " . $mailb ."\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 suessfully!</b></p>"; }else{ echo "<p><b>Email could not be sent. </b></p>"; } ?> <div align="center"> <table><tr><td width="66"><div align="right"><b>To</b></div></td> <td width="308"><b> <?php echo $mailtoname . " [". $mailtomail . " ]";?> </b></td></tr> <tr><td width="66"><div align="right"><b>CC</b></div></td> <td width="308"><b><?php echo $mail;?></b></td></tr> <tr><td width="66"><div align="right"><b>BCC</b></div></td> <td width="308"><b><?php echo $mailb; ?></b></td></tr> <tr><td width="66"><div align="right"><b>Priority</b></div></td> <td width="308"><b><?php echo $mailpriority;?></b></td></tr> <tr><td width="66"><div align="right"><b>Subject </b></div></td> <td width="308"><b><?php echo $mailsubject;?></b></td></tr> <tr><td width="66"><div align="right"><b>Message</b></div></td> <td width="308"><b><?php echo $mailbody;?></b></td></tr> </table> </div> </body> </html>
希望本文所述对大家的php程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程