linuxaid wing
本类可以用与于email的群发,测试的环境是linux,系统需要安装sendmail才能使用
<?php
if ( ! defined( 'mail_class_defined' ) ) {
define('mail_class_defined', 1 );
class email {
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;
// 定义收件人
if ( is_array($tolist) ) {
$this->to = join( $tolist, "," );
} else {
$this->to = $tolist;
}
// 定义抄送名单
if ( is_array($cclist) && sizeof($cclist) ) {
$this->cc = join( $cclist, "," );
} elseif ( $cclist ) {
$this->cc = $cclist;
}
// 定义密码抄送名单
if ( is_array($bcclist) && sizeof($bcclist) ) {
$this->bcc = join( $bcclist, "," );
} elseif ( $bcclist ) {
$this->bcc = $bcclist;
}
}
// 发送函数
// 利用php中的mail()函数发送email
function send () {
//发件人
$this->headers = "from: " . $this->sender . " ";
// 回复地址
if ( $this->replyto ) {
$this->headers .= "reply-to: " . $this->replyto . " ";
}
// 抄送
if ( $this->cc ) {
$this->headers .= "cc: " . $this->cc . " ";
}
// 秘密抄送
if ( $this->bcc ) {
$this->headers .= "bcc: " . $this->bcc . " ";
}
return mail ( $this->to, $this->subject, $this->message, $this->headers ); //返回结果
}
}
}
?>
说明:
参数说明
----------
- 以下几个参数是必须的:subject, message, sendername, senderemail 和 tolist
- 这几个参数则是可选的:cclist, bcclist 和 replyto
- tolist, cclist 和 bcclist 必须是有效的email地址
例如
-------
$m = new email ( "问候", 主题
"你好吗?", 正文
"wing", 发件人姓名
"[email protected]", 发件人email
array("[email protected]", "[email protected]”), 收件人
"[email protected]" 抄送
);
print "邮件已发送,发送结果:" . $m->send();
新闻热点
疑难解答