1
|
<?php
|
2
|
require_once (APP_PATH . "/application/library/PhpMailer/PHPMailer.php");
|
3
|
use PhpMailer\PHPMailer;
|
4
|
|
5
|
class MailModel extends Publicapi
|
6
|
{
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
public function init()
|
15
|
{
|
16
|
parent::init();
|
17
|
}
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
public function mailSend($mail, $content)
|
23
|
{
|
24
|
$keyName = $this->_config->v . "PARAMETERS";
|
25
|
$arrParameters = $this->_memcache->get($keyName);
|
26
|
|
27
|
if ($arrParameters === false) {
|
28
|
|
29
|
$arrParameters = $this->memcacheParameters();
|
30
|
}
|
31
|
|
32
|
|
33
|
$smtp_ip = isset($arrParameters['smtp_ip']) ? $arrParameters['smtp_ip'] : '';
|
34
|
|
35
|
$smtp_port = isset($arrParameters['smtp_port']) ? $arrParameters['smtp_port'] : '';
|
36
|
|
37
|
$smtp_username = isset($arrParameters['smtp_username']) ? $arrParameters['smtp_username'] : '';
|
38
|
|
39
|
$smtp_password = isset($arrParameters['smtp_password']) ? $arrParameters['smtp_password'] : '';
|
40
|
|
41
|
$alarm_mail_title = isset($arrParameters['alarm_mail_title']) ? $arrParameters['alarm_mail_title'] : '标题';
|
42
|
|
43
|
$smtp_NetworkAgent = isset($arrParameters['smtp_NetworkAgent']) ? $arrParameters['smtp_NetworkAgent'] : '';
|
44
|
|
45
|
$smtp_NetworkAgentIp = isset($arrParameters['smtp_NetworkAgentIp']) ? $arrParameters['smtp_NetworkAgentIp'] : '';
|
46
|
|
47
|
$smtp_NetworkAgentPort = isset($arrParameters['smtp_NetworkAgentPort']) ? $arrParameters['smtp_NetworkAgentPort'] : '';
|
48
|
|
49
|
$smtp_NetworkAgentUsername = isset($arrParameters['smtp_NetworkAgentUsername']) ? $arrParameters['smtp_NetworkAgentUsername'] : '';
|
50
|
|
51
|
$smtp_NetworkAgentPassword = isset($arrParameters['smtp_NetworkAgentPassword']) ? $arrParameters['smtp_NetworkAgentPassword'] : '';
|
52
|
|
53
|
return $this->send_mail($mail, $smtp_username, $smtp_password, $smtp_ip, $smtp_port, $content, $alarm_mail_title, $smtp_NetworkAgent, $smtp_NetworkAgentIp, $smtp_NetworkAgentPort, $smtp_NetworkAgentUsername, $smtp_NetworkAgentPassword);
|
54
|
}
|
55
|
|
56
|
|
57
|
|
58
|
|
59
|
|
60
|
|
61
|
|
62
|
|
63
|
|
64
|
|
65
|
|
66
|
|
67
|
|
68
|
|
69
|
|
70
|
|
71
|
|
72
|
|
73
|
|
74
|
|
75
|
public function send_mail($AddAddress, $username, $password, $smtp, $port, $content, $alarm_mail_title, $smtp_NetworkAgent = '', $smtp_NetworkAgentIp = '', $smtp_NetworkAgentPort = '', $smtp_NetworkAgentUsername = '', $smtp_NetworkAgentPassword = '')
|
76
|
{
|
77
|
$pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
|
78
|
$domain_name = preg_replace($pattern, "$2", $username);
|
79
|
$FromName = preg_replace($pattern, "$1", $username);
|
80
|
|
81
|
$Subject = $alarm_mail_title;
|
82
|
$Subject = "=?utf-8?B?" . base64_encode($Subject) . "?=";
|
83
|
|
84
|
$body = $content;
|
85
|
;
|
86
|
$body = preg_replace('/\\\/', '', $body);
|
87
|
|
88
|
$mail = new PHPMailer();
|
89
|
|
90
|
|
91
|
$mail->IsSMTP();
|
92
|
$mail->SMTPAuth = true;
|
93
|
$mail->SMTPKeepAlive = true;
|
94
|
$mail->Host = $smtp;
|
95
|
$mail->Port = $port;
|
96
|
$mail->CharSet = "UTF-8";
|
97
|
if ($port == 465) {
|
98
|
$mail->SMTPSecure = 'ssl';
|
99
|
} else if ($port == 25) {
|
100
|
$mail->SMTPAutoTLS = false;
|
101
|
$mail->SMTPSecure = false;
|
102
|
$mail->SMTPAuth = false;
|
103
|
$mail->SMTPOptions = array(
|
104
|
'ssl' => array(
|
105
|
'verify_peer' => false,
|
106
|
'verify_peer_name' => false,
|
107
|
'allow_self_signed' => true,
|
108
|
)
|
109
|
);
|
110
|
}
|
111
|
|
112
|
$mail->Username = $username;
|
113
|
$mail->Password = $password;
|
114
|
|
115
|
|
116
|
$mail->From = $username;
|
117
|
$mail->FromName = $FromName;
|
118
|
$mail->Subject = $Subject;
|
119
|
$mail->AltBody = $body;
|
120
|
$mail->WordWrap = 50;
|
121
|
$mail->MsgHTML($body);
|
122
|
|
123
|
|
124
|
$mail->AddReplyTo($username, $FromName);
|
125
|
|
126
|
|
127
|
$mail->AddAddress($AddAddress, $AddAddress);
|
128
|
|
129
|
|
130
|
$mail->IsHTML(true);
|
131
|
|
132
|
if ($smtp_NetworkAgent) {
|
133
|
if (empty($smtp_NetworkAgentUsername)) {
|
134
|
|
135
|
$mail->proxy = array(
|
136
|
'proxyHost' => $smtp_NetworkAgentIp,
|
137
|
'proxyPort' => $smtp_NetworkAgentPort
|
138
|
);
|
139
|
} else {
|
140
|
|
141
|
$mail->proxy = array(
|
142
|
'proxyHost' => $smtp_NetworkAgentIp,
|
143
|
'proxyPort' => $smtp_NetworkAgentPort,
|
144
|
'proxyUsername' => $smtp_NetworkAgentUsername,
|
145
|
'proxyPassword' => $smtp_NetworkAgentPassword
|
146
|
);
|
147
|
}
|
148
|
}
|
149
|
|
150
|
|
151
|
$str = '';
|
152
|
if (! $mail->Send()) {
|
153
|
$str = $mail->ErrorInfo;
|
154
|
}
|
155
|
|
156
|
return $str;
|
157
|
}
|
158
|
}
|