• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP中的类-邮件群发_php

php 搞代码 7年前 (2018-06-21) 166次浏览 已收录 0个评论

 

linuxaid Wing

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

<?php  

http://www.gaodaima.com/47504.htmlPHP中的类-邮件群发_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”,                    
发件人姓名  
                   “[email protected]“,          
发件人email  
                   array(“[email protected]”, “[email protected]),  
收件人  
                   “[email protected]”      
抄送
                  );  
 
      print “
邮件已发送,发送结果:” . $m->send();  

欢迎大家阅读《PHP中的类-邮件群发_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP中的类-邮件群发_php

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址