频道直达 - 专题 - 新闻 - 基础 - 高级 - 安装 - 技巧 - 数据库 - 手册 - PHP - Linux - Java - MySQL - Apache - 麻辣堂 - 狼盟 - Rails社群 - 搜索 - 下载 - 开源 - 论坛
PHP开发资源网 主页>>高级应用>> 收藏此文 | 收藏本站 | 设为首页

给多个地址发邮件的PHP类

来源:www.phpres.com 作者:Angelover 出处:www.phpres.com 2007-8-5 09:29:29 进入讨论组
关 键 词: 邮件 地址 多个 // ccList bccList if the toList mail

<?php  

////////////////////////////////////////////////////////////  
//   EmailClass 0.5  
//   class for sending mail  
//  
//   Paul Schreiber  
//   php@paulschreiber.com  
//   http://paulschreiber.com/  
//  
//   parameters  
//   ----------  
//   - subject, message, senderName, senderEmail and toList are required  
//   - ccList, bccList and replyTo are optional  
//   - toList, ccList and bccList can be strings or arrays of strings  
//     (those strings should be valid email addresses  
//  
//   example  
//   -------  
//   $m = new email ( "hello there",            // subject  
//                    "how are you?",           // message body  
//                    "paul",                   // sender's name  
//                    "foo@foobar.com",         // sender's email  
//                    array("paul@foobar.com", "foo@bar.com"), // To: recipients  
//                    "paul@whereever.com"      // Cc: recipient  
//                   );  
//  
//       print "mail sent, result was" . $m->send();  
//  
//  
//  

if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) {  
define('MAIL_CLASS_DEFINED', 1 );  

class email {  

// the constructor!  
function email ( $subject, $message, $senderName, $senderEmail, $toList, $ccList=0, $bccList=0, $replyTo=0) {  
$this->sender = $senderName . " <$senderEmail>";  
$this->replyTo = $replyTo;  
$this->subject = $subject;  
$this->message = $message;  

// set the To: recipient(s)  
if ( is_array($toList) ) {  
$this->to = join( $toList, "," );  
} else {  
$this->to = $toList;  
}  

// set the Cc: recipient(s)  
if ( is_array($ccList) && sizeof($ccList) ) {  
$this->cc = join( $ccList, "," );  
} elseif ( $ccList ) {  
$this->cc = $ccList;  
}  

// set the Bcc: recipient(s)  
if ( is_array($bccList) && sizeof($bccList) ) {  
$this->bcc = join( $bccList, "," );  
} elseif ( $bccList ) {  
$this->bcc = $bccList;  
}  

}  

// send the message; this is actually just a wrapper for   
// PHP's mail() function; heck, it's PHP's mail function done right :-)  
// you could override this method to:  
// (a) use sendmail directly  
// (b) do SMTP with sockets  
function send () {  
// create the headers needed by PHP's mail() function  

// sender  
$this->headers = "From: " . $this->sender . "n";  

// reply-to address  
if ( $this->replyTo ) {  
$this->headers .= "Reply-To: " . $this->replyTo . "n";  
}  

// Cc: recipient(s)  
if ( $this->cc ) {  
$this->headers .= "Cc: " . $this->cc . "n";  
}  

// Bcc: recipient(s)  
if ( $this->bcc ) {  
$this->headers .= "Bcc: " . $this->bcc . "n";  
}  

return mail ( $this->to, $this->subject, $this->message, $this->headers );  
}  
}  

}  
?>欢迎进入PHP开发资源论坛讨论。
收藏此文】【 】【打印】【关闭
相关文章
图文推荐
论 坛 资 源
PHP开发资源网奋斗目标
阅读排行:
热门技术文档
最新图文档
本站编辑推荐:(本站开通Delphi4PHP专区,欢迎进入论坛交流!)
编缉最近更新文章
网站赞助商
搜索您感兴趣的内容
 
   网站首页 -  网站地图 -  网站合作 -  手册中心 -  通用网址 -  网站论坛 -  网站投稿 -  友情链接 -  帮助中心
版权所有:PHP开发资源网 © 2003-2008 通用网址:PHP资源网 合作媒体: 赛迪网IT技术
互联网违法和不良信息举报中心 | 不良信息举报信箱