给多个地址发邮件的类


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 相关文章推荐
Blitz templates 最快的PHP模板引擎
Apr 06 PHP
深入file_get_contents与curl函数的详解
Jun 25 PHP
yii操作session实例简介
Jul 31 PHP
php中异常处理方法小结
Jan 09 PHP
php截取中文字符串函数实例
Feb 23 PHP
分享php分页的功能模块
Jun 16 PHP
PHP的Yii框架中移除组件所绑定的行为的方法
Mar 18 PHP
示例详解Laravel的注册重构
Aug 14 PHP
php之可变函数的实例详解
Sep 13 PHP
PHP长连接实现与使用方法详解
Feb 11 PHP
PHP面向对象五大原则之里氏替换原则(LSP)详解
Apr 08 PHP
PHP isset()及empty()用法区别详解
Aug 29 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入门学习知识点五 关于php数组的几个基本操作
2011/07/14 PHP
将时间以距今多久的形式表示,PHP,js双版本
2012/09/25 PHP
PHP构造二叉树算法示例
2017/06/21 PHP
php-msf源码详解
2017/12/25 PHP
laravel 创建命令行命令的图文教程
2019/10/23 PHP
Alliance vs Liquid BO3 第二场2.13
2021/03/10 DOTA
jquery last-child 列表最后一项的样式
2010/01/22 Javascript
基于Jquery的仿Windows Aero弹出窗(漂亮的关闭按钮)
2010/09/28 Javascript
详解JavaScript时间格式化
2015/12/23 Javascript
Bootstrap笔记之缩略图、警告框实例详解
2017/03/09 Javascript
layer子层给父层页面元素赋值,以达到向父层页面传值的效果实例
2017/09/22 Javascript
JavaScript异步加载问题总结
2018/02/17 Javascript
VUE v-for循环中每个item节点动态绑定不同函数的实例
2018/09/26 Javascript
深入浅析javascript函数中with
2018/10/28 Javascript
js中this的指向问题归纳总结
2018/11/28 Javascript
VeeValidate 的使用场景以及配置详解
2019/01/11 Javascript
如何优雅地在vue中添加权限控制示例详解
2019/03/07 Javascript
vue-列表下详情的展开与折叠案例
2020/07/28 Javascript
[44:39]2014 DOTA2国际邀请赛中国区预选赛 NE VS CNB
2014/05/21 DOTA
[56:01]2018DOTA2亚洲邀请赛 3.31 小组赛 B组 Effect vs EG
2018/03/31 DOTA
Django在Win7下的安装及创建项目hello word简明教程
2014/07/14 Python
浅析python3字符串格式化format()函数的简单用法
2018/12/07 Python
python Django框架实现web端分页呈现数据
2019/10/31 Python
Python+Kepler.gl轻松制作酷炫路径动画的实现示例
2020/06/02 Python
python要安装在哪个盘
2020/06/15 Python
台湾团购、宅配和优惠券:17Life
2017/08/14 全球购物
Bath & Body Works阿联酋:在线购买沐浴和身体用品
2021/02/27 全球购物
Servlet都有哪些方法?主要作用是什么?
2014/03/04 面试题
毕业生自荐信的主要内容
2013/10/29 职场文书
中层干部培训方案
2014/06/16 职场文书
会计试用期自我评价
2014/09/19 职场文书
小学生2014国庆节演讲稿:祖国在我心中
2014/09/21 职场文书
初中体育课教学反思
2016/02/16 职场文书
2016社区平安家庭事迹材料
2016/02/26 职场文书
奖学金申请书(范文)
2019/08/14 职场文书
vue实现Toast组件轻提示
2022/04/10 Vue.js