给多个地址发邮件的类


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 10 PHP
php中sprintf与printf函数用法区别解析
Feb 17 PHP
9段PHP实用功能的代码推荐
Oct 14 PHP
php获取指定日期之间的各个周和月的起止时间
Nov 24 PHP
PHP面向对象详解(三)
Dec 07 PHP
PHP从二维数组得到N层分类树的实现代码
Oct 11 PHP
thinkphp3.2嵌入百度编辑器ueditor的实例代码
Jul 13 PHP
针对thinkPHP5框架存储过程bug重写的存储过程扩展类完整实例
Jun 16 PHP
阿里云的WindowsServer2016上部署php+apache
Jul 17 PHP
PHP实现简易计算器功能
Aug 28 PHP
使用composer命令加载vendor中的第三方类库 的方法
Jul 09 PHP
laravel批量生成假数据的方法
Oct 09 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网站在线人数统计
2008/04/09 PHP
php验证身份证号码正确性的函数
2016/07/20 PHP
使用PHPMailer发送邮件实例
2017/02/15 PHP
javascript function调用时的参数检测常用办法
2010/02/26 Javascript
JS request函数 用来获取url参数
2010/05/17 Javascript
使用原生javascript创建通用表单验证——更锋利的使用dom对象
2011/09/13 Javascript
document.getElementBy(&quot;id&quot;)与$(&quot;#id&quot;)有什么区别
2013/09/22 Javascript
js控制input框只读实现示例
2014/01/20 Javascript
js中arguments,caller,callee,apply的用法小结
2014/01/28 Javascript
javascript中with()方法的语法格式及使用
2014/08/04 Javascript
通过JS动态创建一个html DOM元素并显示
2014/10/15 Javascript
纯JavaScript代码实现移动设备绘图解锁
2015/10/16 Javascript
JavaScript字符串常用的方法
2016/03/10 Javascript
Nodejs Stream 数据流使用手册
2016/04/17 NodeJs
node.js基于express使用websocket的方法
2017/11/09 Javascript
解决vue打包之后静态资源图片失效的问题
2018/02/21 Javascript
利用nodeJs anywhere搭建本地服务器环境的方法
2018/05/12 NodeJs
jQuery实现当拉动滚动条到底部加载数据的方法分析
2019/01/24 jQuery
通过JQuery,JQueryUI和Jsplumb实现拖拽模块
2019/06/18 jQuery
vue 保留两位小数 不能直接用toFixed(2) 的解决
2020/08/07 Javascript
微信小程序实现点击页面出现文字
2020/09/21 Javascript
Python设计足球联赛赛程表程序的思路与简单实现示例
2016/06/28 Python
python 3.5下xadmin的使用及修复源码bug
2017/05/10 Python
matplotlib设置legend图例代码示例
2017/12/19 Python
浅谈python中对于json写入txt文件的编码问题
2018/06/07 Python
深入解析Python小白学习【操作列表】
2019/03/23 Python
Keras官方中文文档:性能评估Metrices详解
2020/06/15 Python
解决html5中的video标签ios系统中无法播放使用的问题
2020/08/10 HTML / CSS
汉森冲浪板:Hansen Surfboards
2018/05/19 全球购物
品恩科技软件测试面试题
2014/10/26 面试题
医学护理系毕业生求职信
2013/10/01 职场文书
2014年学校国庆主题活动方案
2014/09/16 职场文书
如何签定毕业生就业协议书
2014/09/28 职场文书
论文致谢词范文
2015/05/14 职场文书
学法用法心得体会(2016推荐篇)
2016/01/21 职场文书
毕业生就业推荐表自我鉴定
2019/06/20 职场文书