给多个地址发邮件的类


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 输出简单动态WAP页面
Jun 09 PHP
PHP Zip压缩 在线对文件进行压缩的函数
May 26 PHP
详解php的魔术方法__get()和__set()使用介绍
Sep 19 PHP
php header功能的使用
Oct 28 PHP
重新认识php array_merge函数
Aug 31 PHP
php实现上传图片保存到数据库的方法
Feb 11 PHP
用PHP代码在网页上生成图片
Jul 01 PHP
CI框架支持$_GET的两种实现方法
May 18 PHP
php 防止表单重复提交两种实现方法
Nov 03 PHP
php 使用mpdf实现指定字段配置字体样式的方法
Jul 29 PHP
thinkphp5框架结合mysql实现微信登录和自定义分享链接与图文功能示例
Aug 13 PHP
PHP过滤器 filter_has_var() 函数用法实例分析
Apr 23 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将任何格式视频转为flv的代码
2009/09/03 PHP
php加速器eAccelerator的配置参数、API详解
2014/05/05 PHP
PHP实现即时输出、实时输出内容方法
2015/05/27 PHP
Yii2实现多域名跨域同步登录退出
2017/02/04 PHP
PHP如何获取Cookie并实现模拟登录
2020/07/16 PHP
浅析return false的正确使用
2013/11/04 Javascript
jQuery扁平化风格下拉框美化插件FancySelect使用指南
2015/02/10 Javascript
JavaScript实现DIV层拖动及动态增加新层的方法
2015/05/12 Javascript
使用AJAX实现Web页面进度条的实例分享
2016/05/06 Javascript
checkbox批量选中,获取选中项的值的简单实例
2016/06/28 Javascript
AngularJS框架的ng-app指令与自动加载实现方法分析
2017/01/04 Javascript
微信小程序使用input组件实现密码框功能【附源码下载】
2017/12/11 Javascript
详解webpack编译速度提升之DllPlugin
2019/02/05 Javascript
react 移动端实现列表左滑删除的示例代码
2019/07/04 Javascript
VUE 解决mode为history页面为空白的问题
2019/11/01 Javascript
[35:26]DOTA2上海特级锦标赛B组小组赛#2 VG VS Fnatic第三局
2016/02/26 DOTA
详解Python程序与服务器连接的WSGI接口
2015/04/29 Python
详解Python的Django框架中的模版相关知识
2015/07/15 Python
python实现redis三种cas事务操作
2017/12/19 Python
Pycharm如何打断点的方法步骤
2019/06/13 Python
使用python实现unix2dos和dos2unix命令的例子
2019/08/13 Python
python使用OpenCV模块实现图像的融合示例代码
2020/04/10 Python
css3实现六边形边框的实例代码
2019/05/24 HTML / CSS
一篇文章带你学习CSS3图片边框
2020/11/04 HTML / CSS
Html5踩坑记之mandMobile使用小记
2020/04/02 HTML / CSS
葡萄牙鞋子品牌:Fair
2016/12/10 全球购物
自我评价个人范文
2013/12/16 职场文书
2014入党积极分子批评与自我批评思想报告
2014/10/06 职场文书
教师党的群众路线教育实践活动剖析材料
2014/10/09 职场文书
奖学金个人总结
2015/03/04 职场文书
酒店前台接待岗位职责
2015/04/02 职场文书
社区青年志愿者活动总结
2015/05/06 职场文书
2015秋学期开学寄语
2015/05/28 职场文书
PHP命令行与定时任务
2021/04/01 PHP
基于Redis延迟队列的实现代码
2021/05/13 Redis
OpenCV实现普通阈值
2021/11/17 Java/Android