首页 > 后端开发 > php教程 > php带抄送和密件抄送的邮件发送方法,密件邮件发送_PHP教程

php带抄送和密件抄送的邮件发送方法,密件邮件发送_PHP教程

WBOY
发布: 2016-07-13 10:01:56
原创
1109 人浏览过

php带抄送和密件抄送的邮件发送方法,密件邮件发送

本文实例讲述了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=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>
 <&#63;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>";
  }
&#63;>
<div align="center">
<table><tr><td width="66"><div align="right"><b>To</b></div></td>
       <td width="308"><b>
   <&#63;php echo $mailtoname . " [". $mailtomail . " ]";&#63;>
   </b></td></tr>
     <tr><td width="66"><div align="right"><b>CC</b></div></td>
       <td width="308"><b><&#63;php echo $mailcc;&#63;></b></td></tr>
     <tr><td width="66"><div align="right"><b>BCC</b></div></td>
       <td width="308"><b><&#63;php echo $mailbcc; &#63;></b></td></tr>
     <tr><td width="66"><div align="right"><b>Priority</b></div></td>
       <td width="308"><b><&#63;php echo $mailpriority;&#63;></b></td></tr>
     <tr><td width="66"><div align="right"><b>Subject </b></div></td>
       <td width="308"><b><&#63;php echo $mailsubject;&#63;></b></td></tr>
     <tr><td width="66"><div align="right"><b>Message</b></div></td>
       <td width="308"><b><&#63;php echo $mailbody;&#63;></b></td></tr>
</table>
</div>
</body>
</html>
登录后复制

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/970993.htmlTechArticlephp带抄送和密件抄送的邮件发送方法,密件邮件发送 本文实例讲述了php带抄送和密件抄送的邮件发送方法。分享给大家供大家参考。具体分...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板