给多个地址发邮件的类


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 相关文章推荐
php面向对象全攻略 (四)构造方法与析构方法
Sep 30 PHP
初步介绍PHP扩展开发经验分享
Sep 06 PHP
PHP彩蛋信息介绍和阻止泄漏的方法(隐藏功能)
Aug 06 PHP
Linux操作系统安装LAMP环境
Jun 26 PHP
帝国cms目录结构分享
Jul 06 PHP
php多线程实现方法及用法实例详解
Oct 26 PHP
thinkPHP中验证码的简单实现方法
Dec 05 PHP
PHP实现的各类hash算法长度及性能测试实例
Aug 27 PHP
PHP递归的三种常用方式
Feb 28 PHP
php面试实现反射注入的详细方法
Sep 30 PHP
PHP全局使用Laravel辅助函数dd
Dec 26 PHP
聊聊 PHP 8 新特性 Attributes
Aug 19 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
日本因肺炎疫情影响,这几部动漫推延播放!
2020/03/03 日漫
用PHP伪造referer突破网盘禁止外连的代码
2008/06/15 PHP
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)
2014/11/08 PHP
php使用gettimeofday函数返回当前时间并存放在关联数组里
2015/03/19 PHP
PHP错误处理函数
2016/04/03 PHP
php实现的简单数据库操作Model类
2016/11/16 PHP
ThinkPHP实现生成和校验验证码功能
2017/04/28 PHP
PHP实践教程之过滤、验证、转义与密码详解
2017/07/24 PHP
select组合框option的捕捉实例代码
2008/09/30 Javascript
基于jquery的一个拖拽到指定区域内的效果
2011/09/21 Javascript
jQuery对象初始化的传参方式
2015/02/26 Javascript
javascript中this的四种用法
2015/05/11 Javascript
Javascript闭包与函数柯里化浅析
2016/06/22 Javascript
Vue.js学习示例分享
2017/02/05 Javascript
基于jQuery实现咖啡订单管理简单应用
2017/02/10 Javascript
基于Nodejs利用socket.io实现多人聊天室
2017/02/22 NodeJs
基于Cookie常用操作以及属性介绍
2017/09/07 Javascript
vue-router实现tab标签页(单页面)详解
2017/10/17 Javascript
vue页面跳转后返回原页面初始位置方法
2018/02/11 Javascript
JS弹窗 JS弹出DIV并使整个页面背景变暗功能的实现代码
2018/04/21 Javascript
详解VUE里子组件如何获取父组件动态变化的值
2018/12/26 Javascript
小程序如何使用分包加载的实现方法
2019/05/22 Javascript
Python  连接字符串(join %)
2008/09/06 Python
python去掉空白行的多种实现代码
2018/03/19 Python
解决Django migrate No changes detected 不能创建表的问题
2018/05/27 Python
Python实现捕获异常发生的文件和具体行数
2020/04/25 Python
python实现学生成绩测评系统
2020/06/22 Python
Django正则URL匹配实现流程解析
2020/11/13 Python
python爬虫scrapy图书分类实例讲解
2020/11/23 Python
详解Canvas事件绑定
2018/06/27 HTML / CSS
金融管理应届生求职信
2014/02/20 职场文书
创建文明学校实施方案
2014/03/11 职场文书
幼儿园父亲节活动总结
2015/02/12 职场文书
礼仪培训心得体会
2016/01/22 职场文书
如何写好活动总结
2019/06/21 职场文书
海贼王十大潜力果实,路飞仅排第十,第一可毁世界(震震果实)
2022/03/18 日漫