From 497ada845620562fffc9d78b28bb6ac82b0e0117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B3=BD=E8=BE=89?= <501574022@qq.com> Date: Tue, 10 Mar 2026 16:02:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E9=82=AE=E7=AE=B1=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E4=BB=8D=E7=84=B6=E8=BF=94=E5=9B=9E=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/library/Ems.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/library/Ems.php b/app/common/library/Ems.php index cf33f47..9794cda 100644 --- a/app/common/library/Ems.php +++ b/app/common/library/Ems.php @@ -84,7 +84,7 @@ class Ems return $result; }); } - $result = Event::trigger('ems_send', $ems); + $result = Event::trigger('ems_send', $ems, true); if (!$result) { $ems->delete(); return false; -- Gitee From f25311a5bb2252e0a411f50b99c65a5a1f6a4f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B3=BD=E8=BE=89?= <501574022@qq.com> Date: Tue, 10 Mar 2026 16:19:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:=20=E4=BC=98=E5=8C=96=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=B6=88=E6=81=AF=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Ems.php | 2 +- app/common/library/Ems.php | 16 ++++++++++++++++ extend/badou/Email.php | 20 +++++++++++--------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/api/controller/Ems.php b/app/api/controller/Ems.php index 00afd37..5ec168a 100644 --- a/app/api/controller/Ems.php +++ b/app/api/controller/Ems.php @@ -77,7 +77,7 @@ class Ems extends Api if ($ret) { $this->success(__('发送成功')); } else { - $this->error(__('发送失败')); + $this->error(__('发送失败').' '.Emslib::getLastErrorMessage()); } } diff --git a/app/common/library/Ems.php b/app/common/library/Ems.php index 9794cda..614a3e3 100644 --- a/app/common/library/Ems.php +++ b/app/common/library/Ems.php @@ -34,6 +34,21 @@ class Ems */ protected static $maxCheckNums = 10; + + /** + * 邮件发送异常的消息回执 + * @var string + */ + protected static $errorMessage = ""; + + private static function setErrorMessage($message) + { + self::$errorMessage = $message; + } + public static function getLastErrorMessage() + { + return self::$errorMessage; + } /** * 获取最后一次邮箱发送的数据 * @@ -80,6 +95,7 @@ class Ems ->send(); } catch (PHPMailerException $e) { $result = false; + self::setErrorMessage($e->getMessage()); } return $result; }); diff --git a/extend/badou/Email.php b/extend/badou/Email.php index 903e25b..ccd3aec 100644 --- a/extend/badou/Email.php +++ b/extend/badou/Email.php @@ -5,6 +5,7 @@ namespace badou; use Throwable; use think\facade\Lang; use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\Exception as PHPMailerException; /** * 邮件类 @@ -54,16 +55,17 @@ class Email extends PHPMailer $this->configured = false; } } - if ($this->configured) { - $this->Host = $sysMailConfig['smtp_server']; - $this->SMTPAuth = true; - $this->Username = $sysMailConfig['smtp_user']; - $this->Password = $sysMailConfig['smtp_pass']; - $this->SMTPSecure = $sysMailConfig['smtp_verification'] == 'SSL' ? self::ENCRYPTION_SMTPS : self::ENCRYPTION_STARTTLS; - $this->Port = $sysMailConfig['smtp_port']; - - $this->setFrom($sysMailConfig['smtp_sender_mail'], $sysMailConfig['smtp_user']); + if (!$this->configured) { + throw new PHPMailerException("邮箱配置信息邮件不完整,请先在管理后台配置好邮件服务"); } + $this->Host = $sysMailConfig['smtp_server']; + $this->SMTPAuth = true; + $this->Username = $sysMailConfig['smtp_user']; + $this->Password = $sysMailConfig['smtp_pass']; + $this->SMTPSecure = $sysMailConfig['smtp_verification'] == 'SSL' ? self::ENCRYPTION_SMTPS : self::ENCRYPTION_STARTTLS; + $this->Port = $sysMailConfig['smtp_port']; + + $this->setFrom($sysMailConfig['smtp_sender_mail'], $sysMailConfig['smtp_user']); } /** -- Gitee