...
|
...
|
@@ -161,50 +161,32 @@ class Home extends Base { |
|
|
|
|
|
]);
|
|
|
|
|
|
// 邮件对象
|
|
|
$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']??'');
|
|
|
}
|
|
|
|
|
|
// //回复到那个邮件
|
|
|
// $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']??'');
|
|
|
}
|
|
|
$sendData = [];
|
|
|
$sendData['email'] = $email['email'];
|
|
|
$sendData['nickname'] = $formData['nickname']??'';
|
|
|
$sendData['tos'] = $formData['tos'];
|
|
|
// 抄送
|
|
|
if(($formData['isCc']??0) && !empty($formData['cc'])){
|
|
|
$sendData['cc'] = $formData['cc'];
|
|
|
}
|
|
|
// 密送
|
|
|
if(!empty($formData['bcc'])){
|
|
|
foreach ($formData['bcc'] as $to){
|
|
|
$mail->addBCC($to['email'], $to['name']??'');
|
|
|
}
|
|
|
if(($formData['isBcc']??0) && !empty($formData['bcc'])){
|
|
|
$sendData['bcc'] = $formData['bcc'];
|
|
|
}
|
|
|
|
|
|
|
|
|
//Attachments 附件
|
|
|
$sendData['reply_to'] = [];//回复到那个邮件
|
|
|
//Attachments 附件 上传的
|
|
|
$sendData['attachment'] = [];
|
|
|
$attachment = app()->file('attachment');
|
|
|
if($attachment){
|
|
|
foreach ($attachment as $file){
|
|
|
if($file->move()){
|
|
|
// 添加到邮箱中
|
|
|
$mail->addAttachment($file->savePath.$file->saveName, $file->name); //Add attachments
|
|
|
$sendData['attachment'][] = [
|
|
|
'name' => $file->name,
|
|
|
'filename' => $file->name,
|
|
|
'signName' => $file->saveName,
|
|
|
'path' => $file->savePath.$file->saveName
|
|
|
];
|
|
|
}else{
|
|
|
app()->e(['attachment_upload_error',$file->name]);
|
|
|
}
|
...
|
...
|
@@ -212,15 +194,18 @@ class Home extends Base { |
|
|
}
|
|
|
// 远程路径,云文件
|
|
|
$attachmentUrl = app()->request('attachmentUrl');
|
|
|
|
|
|
if(is_array($attachmentUrl)){
|
|
|
foreach ($attachmentUrl as $file){
|
|
|
$file = is_array($file) ? $file : json_decode($file,true);
|
|
|
if(!empty($file['url']) && !empty($file['name'])){
|
|
|
$file = new UploadFile($file['name'],$file['url']);
|
|
|
if($file->move()){
|
|
|
// 添加到邮箱中
|
|
|
$mail->addAttachment($file->savePath.$file->saveName, $file->name); //Add attachments
|
|
|
$sendData['attachment'][] = [
|
|
|
'name' => $file->name,
|
|
|
'filename' => $file->name,
|
|
|
'signName' => $file->saveName,
|
|
|
'path' => $file->savePath.$file->saveName
|
|
|
];
|
|
|
}else{
|
|
|
app()->e(['attachment_upload_error',$file->name]);
|
|
|
}
|
...
|
...
|
@@ -228,26 +213,36 @@ class Home extends Base { |
|
|
|
|
|
}
|
|
|
}
|
|
|
$sendData['receipt'] = empty($formData['receipt']) ? '' : 1;// 回执,阅读后收回执的邮箱
|
|
|
$sendData['priority'] = $formData['priority']??3;// 是否紧急邮件
|
|
|
$sendData['subject'] = $formData['subject'];// //Content 主题,标题
|
|
|
$sendData['body'] = $formData['body'];
|
|
|
|
|
|
// 定时发送时间
|
|
|
$timer = strtotime(app()->request('timerValue','2023-04-10'));
|
|
|
// 是否存草稿
|
|
|
if(app()->request('saveType')=='draft'){
|
|
|
// 保存
|
|
|
$draftid = listsSql::saveDraft($sendData,$email,app()->request('draft_id',0,'intval'));
|
|
|
// 保存失败
|
|
|
if($draftid){
|
|
|
app()->_json(['draft_id'=>$draftid]);
|
|
|
}
|
|
|
app()->e('save_draft_error');
|
|
|
|
|
|
// 回执,阅读后收回执的邮箱
|
|
|
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'];
|
|
|
// 定时发送
|
|
|
else if(app()->request('timer') && $timer > time()){
|
|
|
|
|
|
$mail->isHTML(true); //Set email format to HTML
|
|
|
$mail->Body = $formData['body'];// html格式的内容
|
|
|
|
|
|
// 发送
|
|
|
if($mail->send()){
|
|
|
app()->_json(['messageId' => $mail->getLastMessageID()]);
|
|
|
}else{
|
|
|
// 发送
|
|
|
// $result = MailFun::sendEmail($sendData,$email);
|
|
|
// if($result[0]){
|
|
|
// app()->_json(['messageId' => $result[1]]);
|
|
|
// }
|
|
|
// 错误
|
|
|
app()->e($result[1]);
|
|
|
}
|
|
|
app()->e($mail->ErrorInfo);
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -292,6 +287,12 @@ class Home extends Base { |
|
|
$this->setFlags('seen');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否已回复
|
|
|
* @throws \Lib\Err
|
|
|
* @author:dc
|
|
|
* @time 2023/4/10 16:30
|
|
|
*/
|
|
|
public function answered_2_unanswered(){
|
|
|
$this->setFlags('answered');
|
|
|
}
|
...
|
...
|
|