...
|
...
|
@@ -9,6 +9,8 @@ use Model\bodySql; |
|
|
use Model\emailSql;
|
|
|
use Model\folderSql;
|
|
|
use Model\listsSql;
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
use PHPMailer\PHPMailer\SMTP;
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -149,7 +151,7 @@ class Home extends Base { |
|
|
'attachment|'.__('files_email') => [
|
|
|
'file'=>[
|
|
|
'ext' => [],
|
|
|
'size' => 500,
|
|
|
'size' => 1024*1024*5,
|
|
|
'mine' => []
|
|
|
]
|
|
|
],
|
...
|
...
|
@@ -158,24 +160,76 @@ class Home extends Base { |
|
|
|
|
|
]);
|
|
|
|
|
|
$ret = MailFun::sendEmail(
|
|
|
$email['smtp'],
|
|
|
$email['email'],
|
|
|
base64_decode($email['password']),
|
|
|
$formData['nickname']??'',
|
|
|
$formData['tos'],
|
|
|
$formData['subject'],
|
|
|
$formData['body'],
|
|
|
$formData['attachment']??'',
|
|
|
$formData['receipt']??'',
|
|
|
$formData['priority']??3,
|
|
|
);
|
|
|
// 邮件对象
|
|
|
$mail = new PHPMailer();
|
|
|
//Server settings
|
|
|
$mail->SMTPDebug = SMTP::DEBUG_OFF;//调试输出 SMTP::DEBUG_SERVER; //Enable verbose debug output
|
|
|
$mail->isSMTP(); //Send using SMTP
|
|
|
$mail->Host = $email['smtp']; //Set the SMTP server to send through
|
|
|
$mail->SMTPAuth = true; //Enable SMTP authentication
|
|
|
$mail->Username = $email['email']; //SMTP username
|
|
|
$mail->Password = base64_decode($email['password']); //SMTP password
|
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
|
|
|
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
|
|
$mail->CharSet = 'utf-8';
|
|
|
$mail->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;
|
|
|
|
|
|
//Recipients,设置发件人
|
|
|
$mail->setFrom($email['email'], $formData['nickname']??'');// 显示邮件来自谁
|
|
|
// //设置收件人
|
|
|
foreach ($formData['tos'] as $to){
|
|
|
$mail->addAddress($to['email'], $to['name']??'');
|
|
|
}
|
|
|
|
|
|
if($ret[0]===true) {
|
|
|
app()->_json(['messageId'=>$ret[1]]);
|
|
|
}else {
|
|
|
app()->e($ret[1]);
|
|
|
// //回复到那个邮件
|
|
|
// $mail->addReplyTo($reply_to['email'], $reply_to['name']); //Add a recipient
|
|
|
// // 抄送
|
|
|
if(!empty($formData['cc'])){
|
|
|
foreach ($formData['cc'] as $to){
|
|
|
$mail->addCC($to['email'], $to['name']??'');
|
|
|
}
|
|
|
}
|
|
|
// 密送
|
|
|
if(!empty($formData['bcc'])){
|
|
|
foreach ($formData['bcc'] as $to){
|
|
|
$mail->addBCC($to['email'], $to['name']??'');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//Attachments 附件
|
|
|
$attachment = app()->file('attachment');
|
|
|
if($attachment){
|
|
|
foreach ($attachment as $file){
|
|
|
if($file->move()){
|
|
|
// 添加到邮箱中
|
|
|
$mail->addAttachment($file->savePath.$file->saveName, $file->name); //Add attachments
|
|
|
}else{
|
|
|
app()->e(['attachment_upload_error',$file->name]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 回执,阅读后收回执的邮箱
|
|
|
if(!empty($formData['receipt'])){
|
|
|
$mail->ConfirmReadingTo = true;
|
|
|
}
|
|
|
// 是否紧急邮件
|
|
|
// Options: null (default), 1 = High, 3 = Normal, 5 = low.
|
|
|
$mail->Priority = $formData['priority']??3;
|
|
|
|
|
|
//Content 主题,标题
|
|
|
$mail->Subject = $formData['subject'];
|
|
|
|
|
|
$mail->isHTML(true); //Set email format to HTML
|
|
|
$mail->Body = $formData['body'];// html格式的内容
|
|
|
|
|
|
// 发送
|
|
|
if($mail->send()){
|
|
|
app()->_json(['messageId' => $mail->getLastMessageID()]);
|
|
|
}
|
|
|
app()->e($mail->ErrorInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|