给多个地址发邮件的类


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 相关文章推荐
phpMyAdmin链接MySql错误 个人解决方案
Dec 28 PHP
PHP访问MYSQL数据库封装类(附函数说明)
Dec 04 PHP
PHP设计模式之观察者模式(Observer)详细介绍和代码实例
Apr 08 PHP
PHP制作图形验证码代码分享
Oct 23 PHP
PHP从FLV文件获取视频预览图的方法
Mar 12 PHP
PHP数组相关函数汇总
Mar 24 PHP
yii2 modal弹窗之ActiveForm ajax表单异步验证
Jun 13 PHP
PHP加密技术的简单实现
Sep 04 PHP
PHP插件PHPMailer发送邮件功能
Feb 28 PHP
PHP中Static(静态)关键字功能与用法实例分析
Apr 05 PHP
PHP数组与字符串互相转换实例
May 05 PHP
PHP $O00OO0=urldecode &amp; eval 解密,记一次商业源码的去后门
Sep 13 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读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
2013/08/10 PHP
PHP的引用详解
2015/02/22 PHP
PHP实现懒加载的方法
2015/03/07 PHP
PHP 数组黑名单/白名单实例代码详解
2019/06/04 PHP
javascript学习网址备忘
2007/05/29 Javascript
xml转json的js代码
2012/08/28 Javascript
JQuery slideshow的一个小问题(如何发现及解决过程)
2013/02/06 Javascript
解析Jquery取得iframe中元素的几种方法
2013/07/04 Javascript
基于NodeJS的前后端分离的思考与实践(四)安全问题解决方案
2014/09/26 NodeJs
javascript表单验证和Window详解
2014/12/11 Javascript
浅析JS运动
2015/12/28 Javascript
javascript运算符——逻辑运算符全面解析
2016/06/27 Javascript
jquery实用技巧之输入框提示语句
2016/07/28 Javascript
Bootstrap选项卡动态切换效果
2016/11/28 Javascript
Bootstrap弹出框modal上层的输入框不能获得焦点问题的解决方法
2016/12/13 Javascript
利用Bootstrap实现表格复选框checkbox全选
2016/12/21 Javascript
AngularJS 最常用的八种功能(基础知识)
2017/06/26 Javascript
JavaScript变量声明var,let.const及区别浅析
2018/04/23 Javascript
jQuery事件绑定和解绑、事件冒泡与阻止事件冒泡及弹出应用示例
2019/05/13 jQuery
Python模拟脉冲星伪信号频率实例代码
2018/01/03 Python
局域网内python socket实现windows与linux间的消息传送
2019/04/19 Python
Python OpenCV 调用摄像头并截图保存功能的实现代码
2019/07/02 Python
python 利用pywifi模块实现连接网络破解wifi密码实时监控网络
2019/09/16 Python
Pytorch DataLoader 变长数据处理方式
2020/01/08 Python
使用 Python 在京东上抢口罩的思路详解
2020/02/27 Python
python else语句在循环中的运用详解
2020/07/06 Python
德国著名廉价网上药店:Shop-Apotheke
2017/07/23 全球购物
统计学专业毕业生的自我评价分享
2013/11/28 职场文书
超市中秋节活动方案
2014/02/12 职场文书
什么是就业协议书
2014/04/17 职场文书
廉洁自律演讲稿
2014/05/22 职场文书
庆七一宣传标语
2014/10/08 职场文书
教师见习报告范文
2014/11/03 职场文书
2014年度个人总结范文
2015/03/09 职场文书
详解Java实践之适配器模式
2021/06/18 Java/Android
【海涛教你打dota】体验一超神发条:咱是抢盾专业户
2022/04/01 DOTA