這篇文章主要介紹了php帶抄送和密件抄送的郵件發送方法,涉及php中mail函數的使用技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了php帶抄送和密件抄送的郵件發送方法。分享給大家供大家參考。具體分析如下:
程序中用到了php的mail函數,該函數定義如下:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
如果郵件發送成功返回True,否則返回False
後端php代碼,保存為sendmail.php
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 <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 <[email protected]>n"; $mailheader.= "X-Sender: " . "[email protected]"; $mailheader.= "Return-Path: " . "[email protected]"; 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>"; } ?> <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 $mailcc;?></b></td></tr> <tr><td width="66"><div align="right"><b>BCC</b></div></td> <td width="308"><b><?php echo $mailbcc; ?></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程序設計有所幫助。