PHP中的類-郵件群發

來源:互聯網
上載者:User

 

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();  



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.