程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP 中的類:郵件群發

PHP 中的類:郵件群發

編輯:關於PHP編程

本類可以用與於email的群發,測試的環境是linux,系統需要安裝sendmail才能使用

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地址

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved