diff --git a/trunk/config/config.php b/trunk/config/config.php index 7c91ef5c4d..5ac1f8008d 100644 --- a/trunk/config/config.php +++ b/trunk/config/config.php @@ -21,7 +21,7 @@ * @version $Id$ * @link http://www.zentao.cn */ -$config->version = '0.1 alpha'; // 版本号,切勿修改。 +$config->version = '0.2 alpha'; // 版本号,切勿修改。 $config->debug = true; // 是否打开debug功能。 $config->webRoot = '/'; // web网站的根目录。 $config->encoding = 'UTF-8'; // 网站的编码。 diff --git a/trunk/module/mail/config.php b/trunk/module/mail/config.php new file mode 100644 index 0000000000..2196602c30 --- /dev/null +++ b/trunk/module/mail/config.php @@ -0,0 +1,25 @@ +mail->fromAddress = ''; // 鍙戜欢浜哄湴鍧銆 +$config->mail->fromName = ''; // 鍙戜欢浜哄悕绉般 + +/* 璁剧疆鍙戜俊鏂瑰紡锛岀洰鍓嶆敮鎸乵ail|sendmail|smtp|gmail銆*/ +$config->mail->mta = 'gmail'; + +/* 鏅歋MTP鐨勯厤缃細*/ +if($config->mail->mta == 'smtp') +{ + $config->mail->smtp->debug = 0; // smtp debug绾у埆锛0锛1, 2, 鏁板瓧瓒婂ぇ锛岀骇鍒秺楂樸 + $config->mail->smtp->auth = true; // 鏄惁闇瑕侀獙璇併 + $config->mail->smtp->host = ''; // smtp涓绘満銆 + $config->mail->smtp->port = ''; // 绔彛鍙枫 + $config->mail->smtp->username = ''; // 鐧婚檰鐢ㄦ埛鍚嶏紝鏈夌殑smtp闇瑕佸畬鏁寸殑閭鍦板潃銆 + $config->mail->smtp->password = ''; // 瀵嗙爜銆 +} +/* GMAIL鐨勯厤缃*/ +elseif($config->mail->mta == 'gmail') +{ + $config->mail->gmail->debug = 0; // debug绾у埆锛0锛1, 2, 鏁板瓧瓒婂ぇ锛岀骇鍒秺楂樸 + $config->mail->gmail->username = ""; // GMAIL username + $config->mail->gmail->password = ""; // GMAIL password +} diff --git a/trunk/module/mail/model.php b/trunk/module/mail/model.php index 6ae48b66be..9a8fe4a689 100644 --- a/trunk/module/mail/model.php +++ b/trunk/module/mail/model.php @@ -25,71 +25,115 @@ app->loadClass('phpmailer', $static = true); + $this->setMTA(); } - private function factory($mta, $param = array()) + /* 璁剧疆閭欢浼犺緭浠g悊: MTA銆*/ + public function setMTA() { - $funcName = "set$mta"; - $this->mta = new phpmailer(true); - $this->$funcName($param); + if(self::$instance == null) self::$instance = new phpmailer(true); + $this->mta = self::$instance; + $funcName = "set{$this->config->mail->mta}"; + if(!method_exists($this, $funcName)) echo $this->app->error("The MTA {$this->config->mail->mta} not supported now.", __FILE__, __LINE__, $exit = false); + $this->$funcName(); } - private function setSMTP($param) + /* 鍙戦侀偖浠躲*/ + public function send($subject, $body, $toList, $ccList) + { + try + { + $this->mta->setFrom($this->config->mail->fromAddress, $this->config->mail->fromName); + $this->setSubject($subject); + $this->setTO($toList); + $this->setCC($ccList); + $this->setBody($body); + $this->mta->send(); + } + catch (phpmailerException $e) + { + echo $e->errorMessage(); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + } + + /* SMTP鏂瑰紡銆*/ + private function setSMTP() { $this->mta->isSMTP(); - $this->mta->Host = $param->host; - $this->mta->SMTPAuth = $param->auth; - $this->mta->Username = $param->username; - $this->mta->Password = $param->password; + $this->mta->SMTPDebug = $this->config->mail->smtp->debug; + $this->mta->Host = $this->config->mail->smtp->host; + $this->mta->SMTPAuth = $this->config->mail->smtp->auth; + $this->mta->Username = $this->config->mail->smtp->username; + $this->mta->Password = $this->config->mail->smtp->password; + if(isset($this->config->mail->smtp->port)) $this->mta->Port = $this->config->mail->smtp->port; } - private function setPhpMail($param) + /* PHP Mail鏂瑰紡銆*/ + private function setPhpMail() { $this->mta->isMail(); } - private function setSendMail($param) + /* SendMail鏂瑰紡銆*/ + private function setSendMail() { $this->mta->isSendmail(); } - public function send($subject, $body, $to, $cc) + /* GMAIL鏂瑰紡銆*/ + private function setGMail() { - $this->factory($this->config->mailer->mta); - // Define From Address. - $this->From = $BugConfig["this"]["FromAddress"]; - $this->FromName = $BugConfig["this"]["FromName"]; + $this->mta->isSMTP(); + $this->mta->SMTPDebug = $this->config->mail->gmail->debug; + $this->mta->Host = 'smtp.gmail.com'; + $this->mta->Port = 465; + $this->mta->SMTPSecure = "ssl"; + $this->mta->SMTPAuth = true; + $this->mta->Username = $this->config->mail->gmail->username; + $this->mta->Password = $this->config->mail->gmail->password; + } - // Add To Address. - foreach($ToList as $To) - { - $this->addAddress($To); - } - if(is_array($CCList)) - { - foreach($CCList as $CC) - { - $this->addCC($CC); - } - } - // Add Subject. - $this->Subject = stripslashes($Subject); + /* 璁剧疆鍙戦佸湴鍧銆*/ + private function setTO($toList) + { + foreach($toList as $toName => $toAddress) $this->mta->addAddress($toAddress, $toName); + } - // Set Body. - $this->IsHTML(true); - $this->CharSet = $BugConfig["Charset"]; - $this->Body = stripslashes($Message); - if(!$this->Send()) - { - $MyJS->alert($this->ErrorInfo); - } + /* 璁剧疆鎶勯佸湴鍧銆*/ + private function setCC($ccList) + { + if(!is_array($ccList)) return; + foreach($ccList as $ccName => $ccAddress) $this->mta->addCC($ccAddress, $ccName); + } + + /* 璁剧疆涓婚銆*/ + private function setSubject($subject) + { + $this->mta->Subject = stripslashes($subject); + } + + /* 璁剧疆body銆*/ + private function setBody($body) + { + $this->mta->msgHtml($body); + } + + /* 娓呮鍦板潃鍜岄檮浠躲*/ + private function clear() + { + $this->mta->clearAddresses(); + $this->mta->cearAttachments(); } }