给多个地址发邮件的类


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 相关文章推荐
3
Oct 09 PHP
PHP4中实现动态代理
Oct 09 PHP
又一个php 分页类实现代码
Dec 03 PHP
gd库图片下载类实现下载网页所有图片的php代码
Aug 20 PHP
使用php显示搜索引擎来的关键词
Feb 13 PHP
php5.3提示Function ereg() is deprecated Error问题解决方法
Nov 12 PHP
smarty内置函数config_load用法实例
Jan 22 PHP
PHP实现通过URL提取根域名
Mar 31 PHP
Linux平台php命令行程序处理管道数据的方法
Nov 10 PHP
Smarty模板配置实例简析
Jul 20 PHP
php设计模式之状态模式实例分析【星际争霸游戏案例】
Mar 26 PHP
PHP设计模式(三)建造者模式Builder实例详解【创建型】
May 02 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 MYSQL乱码问题,使用SET NAMES utf8校正
2009/11/30 PHP
ThinkPHP中url隐藏入口文件后接收alipay传值的方法
2014/12/09 PHP
最新最全PHP生成制作验证码代码详解(推荐)
2016/06/12 PHP
使用Yii2实现主从数据库设置
2016/11/20 PHP
php+croppic.js实现剪切上传图片功能
2018/08/14 PHP
JavaScript版DateAdd和DateDiff函数代码
2012/03/01 Javascript
javascript通过class来获取元素实现代码
2013/02/20 Javascript
js取float型小数点后两位数的方法
2014/01/18 Javascript
深入理解JavaScript系列(45):代码复用模式(避免篇)详解
2015/03/04 Javascript
javascript常用正则表达式汇总
2015/07/31 Javascript
如何让Nodejs支持H5 History模式(connect-history-api-fallback源码分析)
2019/05/30 NodeJs
js验证账户名是否重复
2020/05/26 Javascript
python 算法 排序实现快速排序
2012/06/05 Python
python基础教程之获取本机ip数据包示例
2014/02/10 Python
合并百度影音的离线数据( with python 2.3)
2015/08/04 Python
详谈python http长连接客户端
2017/06/12 Python
Python实现正弦信号的时域波形和频谱图示例【基于matplotlib】
2018/05/04 Python
使用PyCharm创建Django项目及基本配置详解
2018/10/24 Python
python字符串替换第一个字符串的方法
2019/06/26 Python
Python解析json时提示“string indices must be integers”问题解决方法
2019/07/31 Python
python 提取文件指定列的方法示例
2019/08/07 Python
详解python中的生成器、迭代器、闭包、装饰器
2019/08/22 Python
Python使用Pandas读写Excel实例解析
2019/11/19 Python
python实现word文档批量转成自定义格式的excel文档的思路及实例代码
2020/02/21 Python
给Django Admin添加验证码和多次登录尝试限制的实现
2020/07/26 Python
Staples英国官方网站:办公用品一站式采购
2017/10/06 全球购物
Made in Design德国:设计师家具、灯具和装饰
2019/10/31 全球购物
大学生专科学习生活的自我评价
2013/12/07 职场文书
授权委托书范本
2014/04/03 职场文书
出生公证委托书
2014/04/03 职场文书
专题组织生活会发言材料
2014/10/17 职场文书
小学生差生评语
2014/12/29 职场文书
幼儿教师小班个人总结
2015/02/05 职场文书
萤火虫之墓观后感
2015/06/05 职场文书
保护环境的宣传语
2015/07/13 职场文书
导游词之无锡丝业博物馆
2019/11/12 职场文书