|
@@ -9,6 +9,8 @@ use Model\bodySql; |
|
@@ -9,6 +9,8 @@ use Model\bodySql; |
9
|
use Model\emailSql;
|
9
|
use Model\emailSql;
|
10
|
use Model\folderSql;
|
10
|
use Model\folderSql;
|
11
|
use Model\listsSql;
|
11
|
use Model\listsSql;
|
|
|
12
|
+use PHPMailer\PHPMailer\PHPMailer;
|
|
|
13
|
+use PHPMailer\PHPMailer\SMTP;
|
12
|
|
14
|
|
13
|
|
15
|
|
14
|
/**
|
16
|
/**
|
|
@@ -149,7 +151,7 @@ class Home extends Base { |
|
@@ -149,7 +151,7 @@ class Home extends Base { |
149
|
'attachment|'.__('files_email') => [
|
151
|
'attachment|'.__('files_email') => [
|
150
|
'file'=>[
|
152
|
'file'=>[
|
151
|
'ext' => [],
|
153
|
'ext' => [],
|
152
|
- 'size' => 500,
|
154
|
+ 'size' => 1024*1024*5,
|
153
|
'mine' => []
|
155
|
'mine' => []
|
154
|
]
|
156
|
]
|
155
|
],
|
157
|
],
|
|
@@ -158,24 +160,76 @@ class Home extends Base { |
|
@@ -158,24 +160,76 @@ class Home extends Base { |
158
|
|
160
|
|
159
|
]);
|
161
|
]);
|
160
|
|
162
|
|
161
|
- $ret = MailFun::sendEmail(
|
|
|
162
|
- $email['smtp'],
|
|
|
163
|
- $email['email'],
|
|
|
164
|
- base64_decode($email['password']),
|
|
|
165
|
- $formData['nickname']??'',
|
|
|
166
|
- $formData['tos'],
|
|
|
167
|
- $formData['subject'],
|
|
|
168
|
- $formData['body'],
|
|
|
169
|
- $formData['attachment']??'',
|
|
|
170
|
- $formData['receipt']??'',
|
|
|
171
|
- $formData['priority']??3,
|
|
|
172
|
- );
|
163
|
+ // 邮件对象
|
|
|
164
|
+ $mail = new PHPMailer();
|
|
|
165
|
+ //Server settings
|
|
|
166
|
+ $mail->SMTPDebug = SMTP::DEBUG_OFF;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output
|
|
|
167
|
+ $mail->isSMTP(); //Send using SMTP
|
|
|
168
|
+ $mail->Host = $email['smtp']; //Set the SMTP server to send through
|
|
|
169
|
+ $mail->SMTPAuth = true; //Enable SMTP authentication
|
|
|
170
|
+ $mail->Username = $email['email']; //SMTP username
|
|
|
171
|
+ $mail->Password = base64_decode($email['password']); //SMTP password
|
|
|
172
|
+ $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
|
|
|
173
|
+ $mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
|
|
174
|
+ $mail->CharSet = 'utf-8';
|
|
|
175
|
+ $mail->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;
|
|
|
176
|
+
|
|
|
177
|
+ //Recipients,设置发件人
|
|
|
178
|
+ $mail->setFrom($email['email'], $formData['nickname']??'');// 显示邮件来自谁
|
|
|
179
|
+ // //设置收件人
|
|
|
180
|
+ foreach ($formData['tos'] as $to){
|
|
|
181
|
+ $mail->addAddress($to['email'], $to['name']??'');
|
|
|
182
|
+ }
|
173
|
|
183
|
|
174
|
- if($ret[0]===true) {
|
|
|
175
|
- app()->_json(['messageId'=>$ret[1]]);
|
|
|
176
|
- }else {
|
|
|
177
|
- app()->e($ret[1]);
|
184
|
+// //回复到那个邮件
|
|
|
185
|
+// $mail->addReplyTo($reply_to['email'], $reply_to['name']); //Add a recipient
|
|
|
186
|
+// // 抄送
|
|
|
187
|
+ if(!empty($formData['cc'])){
|
|
|
188
|
+ foreach ($formData['cc'] as $to){
|
|
|
189
|
+ $mail->addCC($to['email'], $to['name']??'');
|
|
|
190
|
+ }
|
|
|
191
|
+ }
|
|
|
192
|
+ // 密送
|
|
|
193
|
+ if(!empty($formData['bcc'])){
|
|
|
194
|
+ foreach ($formData['bcc'] as $to){
|
|
|
195
|
+ $mail->addBCC($to['email'], $to['name']??'');
|
|
|
196
|
+ }
|
178
|
}
|
197
|
}
|
|
|
198
|
+
|
|
|
199
|
+
|
|
|
200
|
+ //Attachments 附件
|
|
|
201
|
+ $attachment = app()->file('attachment');
|
|
|
202
|
+ if($attachment){
|
|
|
203
|
+ foreach ($attachment as $file){
|
|
|
204
|
+ if($file->move()){
|
|
|
205
|
+ // 添加到邮箱中
|
|
|
206
|
+ $mail->addAttachment($file->savePath.$file->saveName, $file->name); //Add attachments
|
|
|
207
|
+ }else{
|
|
|
208
|
+ app()->e(['attachment_upload_error',$file->name]);
|
|
|
209
|
+ }
|
|
|
210
|
+ }
|
|
|
211
|
+ }
|
|
|
212
|
+
|
|
|
213
|
+ // 回执,阅读后收回执的邮箱
|
|
|
214
|
+ if(!empty($formData['receipt'])){
|
|
|
215
|
+ $mail->ConfirmReadingTo = true;
|
|
|
216
|
+ }
|
|
|
217
|
+ // 是否紧急邮件
|
|
|
218
|
+// Options: null (default), 1 = High, 3 = Normal, 5 = low.
|
|
|
219
|
+ $mail->Priority = $formData['priority']??3;
|
|
|
220
|
+
|
|
|
221
|
+ //Content 主题,标题
|
|
|
222
|
+ $mail->Subject = $formData['subject'];
|
|
|
223
|
+
|
|
|
224
|
+ $mail->isHTML(true); //Set email format to HTML
|
|
|
225
|
+ $mail->Body = $formData['body'];// html格式的内容
|
|
|
226
|
+
|
|
|
227
|
+ // 发送
|
|
|
228
|
+ if($mail->send()){
|
|
|
229
|
+ app()->_json(['messageId' => $mail->getLastMessageID()]);
|
|
|
230
|
+ }
|
|
|
231
|
+ app()->e($mail->ErrorInfo);
|
|
|
232
|
+
|
179
|
}
|
233
|
}
|
180
|
|
234
|
|
181
|
|
235
|
|