首頁  >  文章  >  後端開發  >  php中實作給多個地址發送郵件的類

php中實作給多個地址發送郵件的類

WBOY
WBOY原創
2016-08-08 09:33:521074瀏覽

////////////////////////////////////////////////// ///////////////////////////////////////////////// /  
//   電子郵件類別 0.5  
//   寄郵件的類別  
//  
//   保羅‧施賴伯  
//   php@paulschreiber.com  
//   http://paulschreiber.com/  
//  
//   參數  
//   ----------  
//   - 主題、訊息、senderName、senderEmail 與 toList 為必填項  
//   - ccList、bccList 和replyTo 是選購的  
//   - toList、ccList 和 bccList 可以是字串或字串陣列  
//     (這些字串應該是有效的電子郵件地址  
//  
//   範例  
//   --------  
//   $m = 新電子郵件 ( "你好",            // 主題  
//                    「你好嗎?」,           //訊息主體  //                    "paul",               //                    "foo@foobar.com",         //寄件者的電子郵件 //                    array("paul@foobar.com", "foo@bar.com"), // 收件者:收件者  
//                    "paul@whereever.com"      ///副本:收件者  
//                   );  
//  
//       列印「郵件已寄,結果為」。 $m->send();  
//  
//  
//  

if ( ! Defined( 'MAIL_CLASS_DEFINED' ) ) {  
        定義('MAIL_CLASS_DEFINED', 1);  

班級電子郵件 {  

        // 建構函數!  
        函數電子郵件($subject、$message、$senderName、$senderEmail、$toList、$ccList=0、$bccList=0、$replyTo=0){  
                $this->sender = $senderName 。 “”;  
                $this->replyTo = $replyTo;  
                $this->subject = $subject;  
                $this->message = $message;  

                // 設定收件者:收件人  
                if ( is_array($toList) ) {  
                        $this->to = join( $toList, "," );  
                } 其他 {  
                        $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() 函數;哎呀,PHP 的郵件功能做得很好:-)  
        // 你可以重寫這個方法:  
        // (a) 直接使用sendmail  
        // (b) 使用套接字執行 SMTP
        函數寄送(){  
                // 建立 PHP 的 mail() 函數所需的標頭  

                // 寄件者
                $this->headers = "寄件者:" . $this->寄件者。 「n」;  

                // 回覆位址  
                if ( $this->replyTo ) {  
                        $this->headers .= "回覆:" 。 $this->replyTo 。 「n」;  
                }  

                // 副本:收件者  
                if ( $this->cc ) {  
                        $this->headers .= "副本:" 。 $this->cc 。 「n」;  
                }  

                // 密件副本:收件者  
                if ( $this->bcc ) {  
                        $this->headers .= "密件副本:" 。 $this->密件抄送。 「n」;  
                }  
          
                return mail ( $this->to, $this->subject, $this->message, $this->headers );  
        }  
}  


}  
?>  

以上就介紹了php中實作給多個地址發郵件的類,包括了發郵件方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn