• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

php带抄送和密件抄送的邮件发送代码

PHP 水墨上仙 1314次浏览

程序中用到了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>
  <?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>";
    }
  ?>
  <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带抄送和密件抄送的邮件发送代码
喜欢 (0)
加载中……