首页 > php教程 > php手册 > 正文

PHP中的类-邮件群发

php中文网
发布: 2016-06-21 09:01:59
原创
1608人浏览过

 

Linuxaid Wing

   
本类可以用与于email的群发,测试的环境是linux,系统需要安装sendmail才能使用

php  

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

class email {  

     
       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;  

               // 定义收件人  
               if ( is_array($toList) ) {  
                       $this->to = join( $toList, "," );  
               } else {  
                       $this->to = $toList;  
               }  

               //
定义抄送名单
               if ( is_array($ccList) && sizeof($ccList) ) {  
                       $this->cc = join( $ccList, "," );  
               } elseif ( $ccList ) {  
                       $this->cc = $ccList;  
               }  
                 
               //
定义密码抄送名单  
               if ( is_array($bccList) && sizeof($bccList) ) {  
                       $this->bcc = join( $bccList, "," );  
               } elseif ( $bccList ) {  
                       $this->bcc = $bccList;  
               }  

       }  

       //
发送函数  
       //
利用php中的mail()函数发送email
       
       function send () {  
//
发件人
                             $this->headers = "From: " . $this->sender . " ";  

               //
回复地址  
               if ( $this->replyTo ) {  
                       $this->headers .= "Reply-To: " . $this->replyTo . " ";  
               }  

               //
抄送  
               if ( $this->cc ) {  
                       $this->headers .= "Cc: " . $this->cc . " ";  
               }  

               //
秘密抄送
               if ( $this->bcc ) {  
                       $this->headers .= "Bcc: " . $this->bcc . " ";  
               }  
         
               return mail ( $this->to, $this->subject, $this->message, $this->headers ); //
返回结果
       }  
}  


}  
?>

说明:


 
参数说明  
  ----------  
  -
以下几个参数是必须的:subject, message, senderName, senderEmail toList  
  -
这几个参数则是可选的:ccList, bccList replyTo  
  - toList, ccList
bccList 必须是有效的email地址
 
 
例如  
  -------  
  $m = new email ( "
问候",             主题  
                   "
你好吗?",            正文  
                   "Wing",                    
发件人姓名  
                   "wing@linuxaid.com.cn",          
发件人email  
                   array("aa@aa.com", "bb@bb.com),  
收件人  
                   "cc@cc.com"      
抄送
                  );  
 
      print "
邮件已发送,发送结果:" . $m->send();  



PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号