首页 > 开发 > PHP > 正文

PHP中的类-邮件群发

2024-05-04 23:02:32
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  •  

    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",                    
    发件人姓名  
                       "[email protected]",          
    发件人email  
                       array("[email protected]", "[email protected]),  
    收件人  
                       "[email protected]"      
    抄送
                      );  
     
          print "
    邮件已发送,发送结果:" . $m->send();  

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表