fix: 修复测试邮件发送错误

This commit is contained in:
Ying
2023-06-19 18:28:27 +08:00
parent 4faee0c9a2
commit 9126f3bad7
2 changed files with 23 additions and 9 deletions

View File

@@ -382,7 +382,6 @@
<button type="button" class="layui-btn layui-btn-primary" lay-ajax="" <button type="button" class="layui-btn layui-btn-primary" lay-ajax=""
data-url="{:url('/index/testCache')}" data-url="{:url('/index/testCache')}"
data-object="host:chost,port:cport,user:cuser,select:cselect,pass:cpass">{:__('测试连接')}</button> data-object="host:chost,port:cport,user:cuser,select:cselect,pass:cpass">{:__('测试连接')}</button>
</div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">

View File

@@ -211,14 +211,29 @@ class EmailDriver
*/ */
public function testEmail(array $config = []): bool public function testEmail(array $config = []): bool
{ {
$this->config = array_merge($this->config, $config); $mail = new PHPMailer();
$this->mail->Host = $this->config['smtp_host']; $mail->CharSet = 'UTF-8';
$this->mail->Port = $this->config['smtp_port']; $mail->IsSMTP();
$this->mail->Username = $this->config['smtp_user']; $mail->SMTPAuth = true;
$this->mail->Password = trim($this->config['smtp_pass']); $mail->SMTPSecure = 'ssl';
$this->mail->SetFrom($this->config['smtp_user'], $this->config['smtp_name']); $mail->SMTPOptions = array(
if (!$this->address($config['smtp_test'])->Subject("测试邮件")->MsgHTML("如果您看到这封邮件,说明测试成功了!")->send()) { 'ssl' => array(
throw new Exception($this->mail->ErrorInfo); 'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = $config['smtp_host'];
$mail->Port = $config['smtp_port'];
$mail->Username = $config['smtp_user'];
$mail->Password = trim($config['smtp_pass']);
$mail->SetFrom($config['smtp_user'], $config['smtp_name']);
$mail->Subject = "测试邮件";
$mail->MsgHTML("如果您看到这封邮件,说明测试成功了!");
$mail->addAddress($config['smtp_test']);
if (!$mail->send()) {
throw new Exception($mail->ErrorInfo);
} }
return true; return true;