|
@@ -1,12 +1,4 @@
|
|
|
<?php
|
|
|
-/*
|
|
|
- * @Descripttion:
|
|
|
- * @version: X3版本
|
|
|
- * @Author: likang
|
|
|
- * @Date: 2022-06-07 10:16:16
|
|
|
- * @LastEditors: sueRimn
|
|
|
- * @LastEditTime: 2022-06-09 09:23:55
|
|
|
- */
|
|
|
|
|
|
namespace catchAdmin\email\model;
|
|
|
|
|
@@ -38,28 +30,28 @@ class Email extends Model
|
|
|
// 软删除
|
|
|
'deleted_at',
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
public function getStatusAttr()
|
|
|
{
|
|
|
return (string) $this->getData('status');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- public function setEmail($emails,$title,$body)
|
|
|
+
|
|
|
+
|
|
|
+ public function setEmail($emails, $title, $body)
|
|
|
{
|
|
|
- $where= [];
|
|
|
- $where[] = ['type','=','email_config'];
|
|
|
- $Host = Db::name("sys_config")->where($where)->where('field','SmtpHost')->value('fieldValue');
|
|
|
- $Username = Db::name("sys_config")->where($where)->where('field','SmtpUserName')->value('fieldValue');
|
|
|
- $Password = Db::name("sys_config")->where($where)->where('field','SmtpPassword')->value('fieldValue');
|
|
|
- $SMTPSecure = Db::name("sys_config")->where($where)->where('field','SMTPSecure')->value('fieldValue');
|
|
|
- $Port =Db::name("sys_config")->where($where)->where('field','SmtpPort')->value('fieldValue');
|
|
|
- $Name = Db::name("sys_config")->where($where)->where('field','Name')->value('fieldValue');
|
|
|
+ $where = [];
|
|
|
+ $where[] = ['type', '=', 'email_config'];
|
|
|
+ $Host = Db::name("sys_config")->where($where)->where('field', 'SmtpHost')->value('fieldValue');
|
|
|
+ $Username = Db::name("sys_config")->where($where)->where('field', 'SmtpUserName')->value('fieldValue');
|
|
|
+ $Password = Db::name("sys_config")->where($where)->where('field', 'SmtpPassword')->value('fieldValue');
|
|
|
+ $SMTPSecure = Db::name("sys_config")->where($where)->where('field', 'SMTPSecure')->value('fieldValue');
|
|
|
+ $Port = Db::name("sys_config")->where($where)->where('field', 'SmtpPort')->value('fieldValue');
|
|
|
+ $Name = Db::name("sys_config")->where($where)->where('field', 'Name')->value('fieldValue');
|
|
|
$mail = new PHPMailer(true);
|
|
|
try {
|
|
|
//服务器配置
|
|
|
- $mail->CharSet ="UTF-8"; //设定邮件编码
|
|
|
+ $mail->CharSet = "UTF-8"; //设定邮件编码
|
|
|
$mail->SMTPDebug = 0; // 调试模式输出
|
|
|
$mail->isSMTP(); // 使用SMTP
|
|
|
$mail->Host = trim($Host); // SMTP服务器
|
|
@@ -68,17 +60,16 @@ class Email extends Model
|
|
|
$mail->Password = trim($Password); // SMTP 密码 部分邮箱是授权码(例如163邮箱)
|
|
|
$mail->SMTPSecure = trim($SMTPSecure); // 允许 TLS 或者ssl协议
|
|
|
$mail->Port = trim($Port); // 服务器端口 25 或者465 具体要看邮箱服务器支持
|
|
|
- $mail->setFrom(trim($Username),$Name); //发件人
|
|
|
+ $mail->setFrom(trim($Username), $Name); //发件人
|
|
|
//$mail->addAddress('aaaa@126.com', 'Joe'); // 收件人
|
|
|
//$mail->addAddress('ellen@example.com'); // 可添加多个收件人
|
|
|
//$mail->addReplyTo('xxxx@163.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致
|
|
|
//$mail->addCC('cc@example.com'); //抄送
|
|
|
//$mail->addBCC('bcc@example.com'); //密送
|
|
|
- foreach($emails as $item)
|
|
|
- {
|
|
|
+ foreach ($emails as $item) {
|
|
|
$mail->addAddress($item);
|
|
|
}
|
|
|
- //发送附件
|
|
|
+ //发送附件
|
|
|
// $mail->addAttachment('../xy.zip'); // 添加附件
|
|
|
// $mail->addAttachment('../thumb-1.jpg', 'new.jpg'); // 发送附件并且重命名
|
|
|
$mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
|
|
@@ -90,12 +81,5 @@ class Email extends Model
|
|
|
} catch (Exception $e) {
|
|
|
echo '邮件发送失败: ', $mail->ErrorInfo;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+}
|