给多个地址发邮件的类


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 strtr() 函数使用说明
Nov 21 PHP
php源码加密 仿微盾PHP加密专家(PHPCodeLock)
May 06 PHP
解析Ubuntu下crontab命令的用法
Jun 24 PHP
phpmyadmin出现Cannot start session without errors问题解决方法
Aug 14 PHP
培养自己的php编码规范
Sep 28 PHP
php生成txt文件实例代码介绍
Apr 28 PHP
PHP socket 模拟POST 请求实例代码
Jul 18 PHP
PHP使用Redis长连接的方法详解
Feb 12 PHP
PHP中抽象类,接口功能、定义方法示例
Feb 26 PHP
浅谈PHP中的Trait使用方法
Mar 22 PHP
tp5(thinkPHP5框架)使用DB实现批量删除功能示例
May 28 PHP
php接口隔离原则实例分析
Nov 11 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实现显示照片exif信息的方法
2014/07/11 PHP
php通过session防url攻击方法
2014/12/10 PHP
PHP中$this和$that指针使用实例
2015/01/06 PHP
document.all的一个比较完整的总结及案例
2013/01/31 Javascript
浅析ajax请求json数据并用js解析(示例分析)
2013/07/13 Javascript
基于js实现投票的实例代码
2015/08/04 Javascript
基于JS快速实现导航下拉菜单动画效果附源码下载
2016/10/27 Javascript
vue移动端实现红包雨效果
2020/06/23 Javascript
详解Webpack多环境代码打包的方法
2018/08/03 Javascript
浅谈Webpack4 Tree Shaking 终极优化指南
2019/11/18 Javascript
Vue中this.$nextTick的作用及用法
2020/02/04 Javascript
原生js拖拽实现图形伸缩效果
2020/02/10 Javascript
springboot+vue实现文件上传下载
2020/11/17 Vue.js
[00:32]2018DOTA2亚洲邀请赛EG出场
2018/04/03 DOTA
Python lxml模块安装教程
2015/06/02 Python
Python的条件语句与运算符优先级详解
2015/10/13 Python
python 时间戳与格式化时间的转化实现代码
2016/03/23 Python
Python爬取三国演义的实现方法
2016/09/12 Python
python中redis查看剩余过期时间及用正则通配符批量删除key的方法
2018/07/30 Python
python 读取dicom文件,生成info.txt和raw文件的方法
2019/01/24 Python
Python处理时间日期坐标轴过程详解
2019/06/25 Python
pandas取出重复数据的方法
2019/07/04 Python
Python生命游戏实现原理及过程解析(附源代码)
2019/08/01 Python
keras分类之二分类实例(Cat and dog)
2020/07/09 Python
CSS3教程(2):网页边框半径和网页圆角
2009/04/02 HTML / CSS
CSS3 毛玻璃效果
2019/08/14 HTML / CSS
美国保健品专家:Life Extension
2018/05/04 全球购物
会计专业毕业生求职信分享
2014/01/03 职场文书
竞选班干部演讲稿
2014/04/24 职场文书
任命书格式
2014/06/05 职场文书
交通事故案件代理词
2015/05/23 职场文书
同意转租证明
2015/06/24 职场文书
2015中秋祝酒词
2015/08/12 职场文书
一起来学习Python的元组和列表
2022/03/13 Python
教你在 Java 中实现 Dijkstra 最短路算法的方法
2022/04/08 Java/Android
使用scrapy实现增量式爬取方式
2022/06/21 Python