php带抄送和密件抄送的邮件发送示例

PHP带抄送和密件抄送的邮件发送代码感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
程序中用到了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


/**
* PHP带抄送和密件抄送的邮件发送代码
*
* @param 
* @arrange 512-笔记网: jb51.cc
**/
<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>
/***   来自编程之家 jb51.cc(jb51.cc)   ***/

相关文章

Hessian开源的远程通讯,采用二进制 RPC的协议,基于 HTTP 传输。可以实现PHP调用Java,Python,C#等多语...
初识Mongodb的一些总结,在Mac Os X下真实搭建mongodb环境,以及分享个Mongodb管理工具,学习期间一些总结...
边看边操作,这样才能记得牢,实践是检验真理的唯一标准.光看不练假把式,光练不看傻把式,边看边练真把式....
在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较。 echo与print的区别: (...
在安装好wampServer后,一直没有使用phpMyAdmin,今天用了一下,phpMyAdmin显示错误:The mbstring exte...
变量是用于存储数据的容器,与代数相似,可以给变量赋予某个确定的值(例如:$x=3)或者是赋予其它的变...