给多个地址发邮件的类


Posted in PHP onOctober 09, 2006

<?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 相关文章推荐
用mysql内存表来代替php session的类
Feb 01 PHP
深入了解PHP类Class的概念
Jun 14 PHP
解析php中的fopen()函数用打开文件模式说明
Jun 20 PHP
完美解决令人抓狂的zend studio 7代码提示(content Assist)速度慢的问题
Jun 20 PHP
php命名空间学习详解
Feb 27 PHP
PHP ajax 异步执行不等待执行结果的处理方法
May 27 PHP
php实现读取和写入tab分割的文件
Jun 01 PHP
thinkPHP下ueditor的使用方法详解
Dec 26 PHP
php版微信公众平台接口参数调试实现判断用户行为的方法
Sep 23 PHP
PHP读取目录树的实现方法分析
Mar 22 PHP
php创建多级目录与级联删除文件的方法示例
Sep 12 PHP
Laravel 解决composer相关操作提示php相关异常的问题
Oct 23 PHP
用PHP调用数据库的存贮过程!
Oct 09 #PHP
PHP脚本的10个技巧(2)
Oct 09 #PHP
PHP脚本的10个技巧(1)
Oct 09 #PHP
图书管理程序(三)
Oct 09 #PHP
一个从别的网站抓取信息的例子(域名查询)
Oct 09 #PHP
一个PHP+MSSQL分页的例子
Oct 09 #PHP
基于文本的留言簿
Oct 09 #PHP
You might like
php session应用实例 登录验证
2009/03/16 PHP
PHP简洁函数(PHP简单明了函数语法)
2012/06/10 PHP
php中使用临时表查询数据的一个例子
2013/02/03 PHP
PHP按行读取文件时删除换行符的3种方法
2014/05/04 PHP
PHP源码分析之变量的存储过程分解
2014/07/03 PHP
图解找出PHP配置文件php.ini的路径的方法
2014/08/20 PHP
PHP+百度AI OCR文字识别实现了图片的文字识别功能
2019/05/08 PHP
Laravel 错误提示本地化的实现
2019/10/22 PHP
js 操作select相关方法函数
2009/12/06 Javascript
Extjs4 关于Store的一些操作(加载/回调/添加)
2013/04/18 Javascript
JavaScript实现表格排序方法
2013/06/14 Javascript
javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
2013/12/17 Javascript
JS判断表单输入是否为空(示例代码)
2013/12/23 Javascript
JavaScript实现的多个图片广告交替显示效果代码
2015/09/04 Javascript
jQuery CSS3自定义美化Checkbox实现代码
2016/05/12 Javascript
Javascript中arguments对象的详解与使用方法
2016/10/04 Javascript
网页中右键功能的实现方法之contextMenu的使用
2017/02/20 Javascript
JavaScript实现二分查找实例代码
2017/02/22 Javascript
ECMAScript6变量的解构赋值实例详解
2017/09/19 Javascript
全站最详细的Vuex教程
2018/04/13 Javascript
Angular事件之不同组件间传递数据的方法
2018/11/15 Javascript
Vue Components 数字键盘的实现
2019/09/18 Javascript
Chrome插件开发系列一:弹窗终结者开发实战
2020/10/02 Javascript
Element el-button 按钮组件的使用详解
2021/02/01 Javascript
详解Python中的多线程编程
2015/04/09 Python
详解详解Python中writelines()方法的使用
2015/05/25 Python
Python字典简介以及用法详解
2016/11/15 Python
python 求1-100之间的奇数或者偶数之和的实例
2019/06/11 Python
Python加密模块的hashlib,hmac模块使用解析
2020/01/02 Python
python中for in的用法详解
2020/04/17 Python
html5 input属性使用示例
2013/06/28 HTML / CSS
html+js 实现markdown编辑器效果
2019/10/23 HTML / CSS
Urban Outfitters德国官网:美国跨国生活方式零售公司
2018/05/21 全球购物
高三高考决心书
2014/03/11 职场文书
个人委托书范文
2015/01/28 职场文书
导游词之苏州盘门景区
2019/11/12 职场文书