建站极客
网络编程 PHP编程 正文
给多个地址发邮件的类
所属分类:
网络编程 / PHP编程
阅读数:
1296
收藏 0
赞 0
分享
<?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 ); } } } ?>
CI框架实现创建自定义类库的方法 这篇文章主要介绍了CI框架实现创建自定义类库的方法,结合实例形式分析了CI框架创建自定义类库的相关原理、步骤、实现方法与操作注意事项,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
CI框架附属类用法分析 这篇文章主要介绍了CI框架附属类用法,结合实例形式分析了CI框架附属类相关资源访问操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
CI框架网页缓存简单用法分析 这篇文章主要介绍了CI框架网页缓存简单用法,结合实例形式分析了CI框架网页缓存的原理,以及开启缓存、删除缓存等操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php实现的PDO异常处理操作分析 这篇文章主要介绍了php实现的PDO异常处理操作,结合实例形式分析了pdo异常处理的相关原理、用法及操作注意事项,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
php PDO属性设置与操作方法分析 这篇文章主要介绍了php PDO属性设置与操作方法,结合实例形式分析了php pdo常见属性功能及相关的设置、获取操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP抽象类基本用法示例 这篇文章主要介绍了PHP抽象类基本用法,结合实例形式分析了php抽象类的概念、原理、定义、使用方法及相关操作注意事项,代码注释包含较为详尽的说明信息,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP面向对象程序设计继承用法简单示例 这篇文章主要介绍了PHP面向对象程序设计继承用法,结合具体实例形式分析了php面向对象程序设计中继承的相关概念、原理、使用技巧与相关操作注意事项,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP实现函数内修改外部变量值的方法示例 这篇文章主要介绍了PHP实现函数内修改外部变量值的方法,涉及php全局变量、传值调用、引用等相关操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP命名空间简单用法示例 这篇文章主要介绍了PHP命名空间简单用法,结合具体实例形式分析了php命名空间的简单定义与使用相关操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多