给多个地址发邮件的类


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里得到前天和昨天的日期的代码
Aug 16 PHP
Joomla下利用configuration.php存储简单数据
May 19 PHP
基于php无限分类的深入理解
Jun 02 PHP
php读取大文件示例分享(文件操作类)
Apr 13 PHP
ThinkPHP公共配置文件与各自项目中配置文件组合的方法
Nov 24 PHP
分享一个Laravel好用的Cache宏
Mar 02 PHP
php获取本周开始日期和结束日期的方法
Mar 09 PHP
PHP实现的QQ空间g_tk加密算法
Jul 09 PHP
Laravel使用memcached缓存对文章增删改查进行优化的方法
Oct 08 PHP
PHP判断表达式中括号是否匹配的简单实例
Oct 22 PHP
java解析json方法总结
May 16 PHP
PHP常用的类封装小结【4个工具类】
Jun 28 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计算十二星座的函数代码
2012/08/21 PHP
php阻止页面后退的方法分享
2014/02/17 PHP
PHP中SERIALIZE和JSON的序列化与反序列化操作区别分析
2016/10/11 PHP
基于jquery的Repeater实现代码
2010/07/17 Javascript
js改变img标签的src属性在IE下没反应的解决方法
2013/07/23 Javascript
jquery 无限级下拉菜单的简单实现代码
2014/02/21 Javascript
jQuery插件StickUp实现网页导航置顶
2015/04/12 Javascript
javascript中递归函数用法注意点
2015/07/30 Javascript
AnjularJS中$scope和$rootScope的区别小结
2016/09/18 Javascript
基于Phantomjs生成PDF的实现方法
2016/11/07 Javascript
jQuery复合事件结合toggle()方法的用法示例
2017/06/10 jQuery
angularjs实现猜大小功能
2017/10/23 Javascript
React/Redux应用使用Async/Await的方法
2017/11/16 Javascript
Vue官方文档梳理之全局配置
2017/11/22 Javascript
vue实现模态框的通用写法推荐
2018/02/26 Javascript
解决vue页面刷新或者后退参数丢失的问题
2018/03/13 Javascript
详解Vue.js中.native修饰符
2018/04/24 Javascript
JavaScript时间与时间戳的转换操作实例分析
2018/12/07 Javascript
了解在JavaScript中将值转换为字符串的5种方法
2019/06/06 Javascript
微信小程序之滑动页面隐藏和显示组件功能的实现代码
2020/06/19 Javascript
[01:10]DOTA2英雄背景故事第四期之混沌法则混沌骑士
2020/07/16 DOTA
Python 过滤字符串的技巧,map与itertools.imap
2008/09/06 Python
轻松实现python搭建微信公众平台
2016/02/16 Python
python 日志增量抓取实现方法
2018/04/28 Python
基于python cut和qcut的用法及区别详解
2019/11/22 Python
解决django migrate报错ORA-02000: missing ALWAYS keyword
2020/07/02 Python
python 如何快速复制序列
2020/09/07 Python
一款基于css3的动画按钮代码教程
2014/11/23 HTML / CSS
从零实现一个自定义html5播放器的示例代码
2017/08/01 HTML / CSS
保时捷设计:Porsche Design
2019/03/30 全球购物
毕业生的求职信范文分享
2013/12/04 职场文书
医学专业本科毕业生自我鉴定
2013/12/28 职场文书
警察正风肃纪剖析材料
2014/10/16 职场文书
妈妈再爱我一次观后感
2015/06/08 职场文书
小学生节约用水倡议书
2019/08/12 职场文书
MySQL索引 高效获取数据的数据结构
2022/05/02 MySQL