Client.php
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Email发送
* @author tongdesheng
*
*/
require_once 'phpmailer/class.phpmailer.php';
class YHMUtils_Email_Client {
private $_mailer = null;
/**
* 对参数进行初始化
*/
public function __construct() {
$this->_mailer = new PHPMailer();
}
/**
* 初始化发送参数
* @param array $smtpParam
*/
private function init($smtpParam) {
$this->_mailer->isSMTP();
$this->_mailer->Host = $smtpParam['host'];
$this->_mailer->Port = $smtpParam['port'];
$this->_mailer->SMTPAuth = $smtpParam['auth'];
$this->_mailer->Username = $smtpParam['username'];
$this->_mailer->Password = $smtpParam['password'];
$this->_mailer->From = $smtpParam['from'];
$this->_mailer->FromName = $smtpParam['fromname'];
$this->_mailer->CharSet = 'utf-8';
$this->_mailer->Encoding = "base64";
}
/**
* 通过模板发送邮件
* @param string $toMail
* @param string $tplName 模板名称
* @param string $tplData 模板数据
*/
public function sendByTpl($toMail, $tplName, $tplData = array()) {
$tplParam = YHMConfig_Email::$tplData[$tplName];
$smtpParam = YHMConfig_Email::${$tplParam['smtp']};
$this->init($smtpParam);
$this->_mailer->Subject = strtr($tplParam['title'], $tplData);
$this->_mailer->Body = strtr($tplParam['content'], $tplData);
$this->_mailer->isHTML(empty($tplParam['is_html']) ? false : $tplParam['is_html']);
$this->_mailer->addAddress($toMail);
$ret = $this->_mailer->send();
if(empty($ret)) {
throw new Exception($this->_mailer->ErrorInfo);
}
return true;
}
}