解决fastadmin发送邮件时出错

前言:

最近做一个课程《免费卡密分发系统》时需要用到邮箱,结果配置明明是对的,但是就是会出错,

好像没人出解决方案,这里我就来做一下,


项目场景:

用户在前端输入邮箱领取卡密时,系统会把卡密内容发到用户邮箱上。


问题描述

根据以往的开发经验,我填的信息是没有错的,但是不知道为啥就报错了。

报错信息:SMTP Server did not respond with anything I recognized

{
  "code": 0,
  "msg": "SMTP Server did not respond with anything I recognized",
  "data": "",
  "url": "",
  "wait": 3
}


解决方案:

修改 vendor/txthinking/mailer/src/Mailer/SMTP.php

在这个文件中的getCode方法中加入这个。

if(substr(trim($str),-8) == "221 Bye.")
{
     return '221';
}

当然这个奉上完整的getCode方法:

protected function getCode()
    {
        while ($str = fgets($this->smtp, 515)) {
            $this->logger && $this->logger->debug("Got: ". $str);
            $this->resultStack[] = $str;
            if(substr(trim($str),-8) == "221 Bye.")
            {
                return '221';
            }
            if(substr($str,3,1) == " ") {
                $code = substr($str,0,3);
                return $code;
            }
        }
        throw new SMTPException("SMTP Server did not respond with anything I recognized");
    }


总结:

检查获取到的响应信息是否以 "221 Bye." 结尾,如果是,则返回状态码 '221',表示成功关闭连接。

这里是网络乞丐

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值