Browse Source

修复邮件发送错误

Karson 4 years ago
parent
commit
6c0ea3a420
2 changed files with 31 additions and 1 deletions
  1. 2 1
      application/common/library/Email.php
  2. 29 0
      application/common/library/Log.php

+ 2 - 1
application/common/library/Email.php

@@ -62,7 +62,8 @@ class Email
         $secureArr = [0 => '', 1 => 'tls', 2 => 'ssl'];
         $secureArr = [0 => '', 1 => 'tls', 2 => 'ssl'];
         $secure = isset($secureArr[$this->options['mail_verify_type']]) ? $secureArr[$this->options['mail_verify_type']] : '';
         $secure = isset($secureArr[$this->options['mail_verify_type']]) ? $secureArr[$this->options['mail_verify_type']] : '';
 
 
-        $this->mail = new Mailer();
+        $logger = isset($this->options['debug']) && $this->options['debug'] ? new Log : null;
+        $this->mail = new Mailer($logger);
         $this->mail->setServer($this->options['mail_smtp_host'], $this->options['mail_smtp_port'], $secure);
         $this->mail->setServer($this->options['mail_smtp_host'], $this->options['mail_smtp_port'], $secure);
         $this->mail->setAuth($this->options['mail_from'], $this->options['mail_smtp_pass']);
         $this->mail->setAuth($this->options['mail_from'], $this->options['mail_smtp_pass']);
 
 

+ 29 - 0
application/common/library/Log.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\common\library;
+
+use Psr\Log\AbstractLogger;
+use think\Hook;
+
+/**
+ * 日志记录类
+ */
+class Log extends AbstractLogger
+{
+
+    /**
+     * Logs with an arbitrary level.
+     *
+     * @param mixed   $level
+     * @param string  $message
+     * @param mixed[] $context
+     *
+     * @return void
+     *
+     * @throws \Psr\Log\InvalidArgumentException
+     */
+    public function log($level, $message, array $context = array())
+    {
+        \think\Log::write($message);
+    }
+}