给多个地址发邮件的类


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 相关文章推荐
杏林同学录(八)
Oct 09 PHP
php基础知识:函数基础知识
Dec 13 PHP
PHP如何解决网站大流量与高并发的问题
Jun 25 PHP
解析如何在PHP下载文件名中解决乱码的问题
Jun 20 PHP
ie与session丢失(新窗口cookie丢失)实测及解决方案
Jul 15 PHP
PHP不用递归遍历目录下所有文件的代码
Jul 04 PHP
php使用递归计算文件夹大小
Dec 24 PHP
php微信开发自定义菜单
Aug 27 PHP
php+mysql+ajax实现单表多字段多关键词查询的方法
Apr 15 PHP
php自定义函数实现统计中文字符串长度的方法小结
Apr 15 PHP
laravel实现分页样式替换示例代码(增加首、尾页)
Sep 22 PHP
PHP children()函数讲解
Feb 03 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
第十三节 对象串行化 [13]
2006/10/09 PHP
理解php Hash函数,增强密码安全
2011/02/25 PHP
PHP转换IP地址到真实地址的方法详解
2013/06/09 PHP
PHP基于mssql扩展远程连接MSSQL的简单实现方法
2016/10/08 PHP
php获取数据库中数据的实现方法
2017/06/01 PHP
thinkphp分页集成实例
2017/07/24 PHP
javascript 操作文件 实现方法小结
2009/07/02 Javascript
Javascript 闭包引起的IE内存泄露分析
2012/05/23 Javascript
点击表单提交时出现jQuery没有权限的解决方法
2014/07/23 Javascript
深入分析下javascript中的[]()+!
2015/07/07 Javascript
js数组去重的5种算法实现
2015/11/04 Javascript
javascript jquery对form元素的常见操作详解
2016/06/12 Javascript
js与jquery分别实现tab标签页功能的方法
2016/11/18 Javascript
JavaScript使用ZeroClipboard操作剪切板
2017/05/10 Javascript
基于jQuery Easyui实现登陆框界面
2017/07/10 jQuery
详解vue 组件之间使用eventbus传值
2017/10/25 Javascript
Mint-UI时间组件起始时间问题及时间插件使用
2018/08/20 Javascript
利用Angular2的Observables实现交互控制的方法
2018/12/27 Javascript
小程序实现新用户判断并跳转激活的方法
2019/05/20 Javascript
学习LayUI时自研的表单参数校验框架案例分析
2019/07/29 Javascript
python传递参数方式小结
2015/04/17 Python
python一行sql太长折成多行并且有多个参数的方法
2018/07/19 Python
flask框架路由常用定义方式总结
2019/07/23 Python
python中的函数递归和迭代原理解析
2019/11/14 Python
pycharm设置当前工作目录的操作(working directory)
2020/02/14 Python
django的autoreload机制实现
2020/06/03 Python
Vilebrequin美国官方网上商店:法国豪华泳装品牌
2020/02/22 全球购物
惠普新加坡官方商店:HP Singapore
2020/04/17 全球购物
《猴子种树》教学反思
2014/02/14 职场文书
学校综治宣传月活动总结
2014/07/02 职场文书
党员自评材料范文
2014/12/17 职场文书
简历自荐信范文
2015/03/09 职场文书
复制别人的成功真的会成功吗?
2019/10/17 职场文书
python基础之停用词过滤详解
2021/04/21 Python
python3中apply函数和lambda函数的使用详解
2022/02/28 Python
动画《朋友游戏》公开佐藤友生绘制的开播纪念绘
2022/04/06 日漫