本文實例講述了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 p align=right b To /b /p /td p Name input name=mailtoname size=35 br / E-mail input name=mailtomail size=35 /p /td /tr p align=right b CC /b /p /td td input name=mailcc size=35 /td /tr p align=right b BCC /b /p /td td input name=mailbcc size=35 /td /tr p align=right b Priority /b /p /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 td p align=right b Subject /b /p /td td input name=mailsubject size=35 /td /tr p align=right b Message /b /p /td td textarea cols=50 name=mailbody rows=7 /textarea /td /tr td colSpan=2 p align=center input name=Submit type=submit value=Submit /p /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.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 p align= center table tr td width= 66 p align= right b To /b /p /td td width= 308 b ?php echo $mailtoname . [ . $mailtomail . ] ? /b /td /tr tr td width= 66 p align= right b CC /b /p /td td width= 308 b ?php echo $mailcc;? /b /td /tr tr td width= 66 p align= right b BCC /b /p /td td width= 308 b ?php echo $mailbcc; ? /b /td /tr tr td width= 66 p align= right b Priority /b /p /td td width= 308 b ?php echo $mailpriority;? /b /td /tr tr td width= 66 p align= right b Subject /b /p /td td width= 308 b ?php echo $mailsubject;? /b /td /tr tr td width= 66 p align= right b Message /b /p /td td width= 308 b ?php echo $mailbody;? /b /td /tr /table /body /html
總結:以上就是本篇文的全部內容,希望能對大家的學習有所幫助。
相關推薦:
php基于cookie實現記錄用戶名和密碼
PHP中數據庫實現更安全的永久登錄、記住我的功能
PHP中使用生成的公鑰、私鑰進行加密解密的方法
以上就是php中mail函數的定義及用法的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答