给多个地址发邮件的类

5年以前  |  阅读数:959 次  |  编程语言:PHP 

<?php

////////////////////////////////////////////////////////////
// EmailClass 0.5
// class for sending mail
//
// Paul Schreiber
// php@paulschreiber.com
// http://paulschreiber.com/
//
// parameters
// ----------
// - subject, message, senderName, senderEmail and toList are required
// - ccList, bccList and replyTo are optional
// - toList, ccList and bccList can be strings or arrays of strings
// (those strings should be valid email addresses
//
// example
// -------
// $m = new email ( "hello there", // subject
// "how are you?", // message body
// "paul", // sender's name
// "foo@foobar.com", // sender's email
// array("paul@foobar.com", "foo@bar.com"), // To: recipients
// "paul@whereever.com" // Cc: recipient
// );
//
// print "mail sent, result was" . $m->send();
//
//
//

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

class email {

    // the constructor!    
    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;    

            // set the To: recipient(s)    
            if ( is_array($toList) ) {    
                    $this->to = join( $toList, "," );    
            } else {    
                    $this->to = $toList;    
            }    

            // set the Cc: recipient(s)    
            if ( is_array($ccList) && sizeof($ccList) ) {    
                    $this->cc = join( $ccList, "," );    
            } elseif ( $ccList ) {    
                    $this->cc = $ccList;    
            }    

            // set the Bcc: recipient(s)    
            if ( is_array($bccList) && sizeof($bccList) ) {    
                    $this->bcc = join( $bccList, "," );    
            } elseif ( $bccList ) {    
                    $this->bcc = $bccList;    
            }    

    }    

    // send the message; this is actually just a wrapper for     
    // PHP's mail() function; heck, it's PHP's mail function done right :-)    
    // you could override this method to:    
    // (a) use sendmail directly    
    // (b) do SMTP with sockets    
    function send () {    
            // create the headers needed by PHP's mail() function    

            // sender    
            $this->headers = "From: " . $this->sender . "\n";    

            // reply-to address    
            if ( $this->replyTo ) {    
                    $this->headers .= "Reply-To: " . $this->replyTo . "\n";    
            }    

            // Cc: recipient(s)    
            if ( $this->cc ) {    
                    $this->headers .= "Cc: " . $this->cc . "\n";    
            }    

            // Bcc: recipient(s)    
            if ( $this->bcc ) {    
                    $this->headers .= "Bcc: " . $this->bcc . "\n";    
            }    

            return mail ( $this->to, $this->subject, $this->message, $this->headers );    
    }    

}

}
?>

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例