您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中mail函数的定义及用法

2025/10/28 17:33:23发布23次查看
这篇文章主要介绍了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> <p align=right><b>to</b></p></td> <td> <p>name <input name=mailtoname size=35><br />e-mail <input name=mailtomail size=35></p></td></tr> <tr> <td> <p align=right><b>cc</b></p></td> <td><input name=mailcc size=35> </td></tr> <tr> <td> <p align=right><b>bcc</b></p></td> <td><input name=mailbcc size=35> </td></tr> <tr> <td> <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> <tr> <td><p align=right><b>subject</b></p></td> <td><input name=mailsubject size=35></td></tr> <tr> <td> <p align=right><b>message</b> </p></td> <td><textarea cols=50 name=mailbody rows=7></textarea></td></tr> <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></p></body></html>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php基于cookie实现记录用户名和密码
php中数据库实现更安全的永久登录、记住我的功能
php中使用生成的公钥、私钥进行加密解密的方法
以上就是php中mail函数的定义及用法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product