前言:
最近做一个课程《免费卡密分发系统》时需要用到邮箱,结果配置明明是对的,但是就是会出错,
好像没人出解决方案,这里我就来做一下,
项目场景:
用户在前端输入邮箱领取卡密时,系统会把卡密内容发到用户邮箱上。
问题描述
根据以往的开发经验,我填的信息是没有错的,但是不知道为啥就报错了。
报错信息: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',表示成功关闭连接。
这里是网络乞丐