给多个地址发邮件的类


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中的加密功能
Oct 09 PHP
杏林同学录(六)
Oct 09 PHP
php UBB 解析实现代码
Nov 27 PHP
探讨PHP中OO之静态关键字以及类常量的详解
Jun 07 PHP
php实现encode64编码类实例
Mar 24 PHP
WordPress中&quot;无法将上传的文件移动至&quot;错误的解决方法
Jul 01 PHP
ThinkPHP表单数据智能写入create方法实例分析
Sep 27 PHP
PHP利用APC模块实现大文件上传进度条的方法
Oct 29 PHP
PHP 输出缓冲控制(Output Control)详解
Aug 25 PHP
php 解析xml 的四种方法详细介绍
Oct 26 PHP
PHP给前端返回一个JSON对象的实例讲解
May 31 PHP
PHP实现的62进制转10进制,10进制转62进制函数示例
Jun 06 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
用文本作数据处理
2006/10/09 PHP
Laravel与CI框架中截取字符串函数
2016/05/08 PHP
简单实现php上传文件功能
2017/09/21 PHP
PHP开启目录引索+fancyindex漂亮目录浏览带搜索功能
2019/09/23 PHP
js中substring和substr的详细介绍与用法
2013/08/29 Javascript
2014年50个程序员最适用的免费JQuery插件
2014/12/15 Javascript
JavaScript与ActionScript3两者的同性与差异性
2016/09/22 Javascript
JavaScript 控制字体大小设置的方法
2016/11/23 Javascript
JS组件系列之MVVM组件 vue 30分钟搞定前端增删改查
2017/04/28 Javascript
Vue2 使用 Echarts 创建图表实例代码
2017/05/18 Javascript
js使用html2canvas实现屏幕截取的示例代码
2017/08/28 Javascript
使用JS和canvas实现gif动图的停止和播放代码
2017/09/01 Javascript
webpack热模块替换(HMR)/热更新的方法
2018/04/05 Javascript
浅析Vue 生命周期
2018/06/21 Javascript
JS实现容器模块左右拖动效果
2020/01/14 Javascript
Python 自动补全(vim)
2014/11/30 Python
使用Protocol Buffers的C语言拓展提速Python程序的示例
2015/04/16 Python
Python求两个文本文件以行为单位的交集、并集与差集的方法
2015/06/17 Python
R vs. Python 数据分析中谁与争锋?
2017/10/18 Python
Python使用win32 COM实现Excel的写入与保存功能示例
2018/05/03 Python
Python判断是否json是否包含一个key的方法
2018/12/31 Python
Python实现CNN的多通道输入实例
2020/01/17 Python
Python中操作各种多媒体,视频、音频到图片的代码详解
2020/06/04 Python
Python 实现将某一列设置为str类型
2020/07/14 Python
澳大利亚时尚前卫设计师珠宝在线:Amber Sceats
2017/10/04 全球购物
洛佩桑酒店官方网站:Lopesan Hotels
2019/04/15 全球购物
介绍一下linux的文件权限
2014/07/20 面试题
英语文学专业学生的自我评价
2013/10/31 职场文书
小学生作文评语大全
2014/04/21 职场文书
秋天的雨教学反思
2014/04/27 职场文书
公开承诺书格式
2014/05/21 职场文书
大学生党课心得体会
2016/01/07 职场文书
CSS3新特性详解(五):多列columns column-count和flex布局
2021/04/30 HTML / CSS
MySQL 可扩展设计的基本原则
2021/05/14 MySQL
JavaScript实例 ODO List分析
2022/01/22 Javascript
如何通过一篇文章了解Python中的生成器
2022/04/02 Python