Laravel 邮件无法发送原因的查找
上一篇文章 Laravel 邮件配置 已经能够成功发送邮件 奈何部署到服务器后尽然无法发送。https://www.jianshu.com/p/459ab4f30c62
话不多说上图。
嗯嗯 看错误 是像端口被禁用了。
Connection could not be established with host smtp.exmail.qq.com
查文档。有一个童鞋一样的问题 链接 https://yq.aliyun.com/ask/65259
嗯禁用了25端口 可是我这个 465端口没有禁用呀。
确认一下
root@www:~# telnet smtp.exmail.qq.com 465
Trying 163.177.72.143...
Connected to smtp.exmail.qq.com.
Escape character is '^]'.
嗯 确实正常
那么就是环境的问题了
换个版本试试。
换成PHP7.2 正常
问题就出在php7.3上了
我们看看 laravel 报错的位置
$streamContext = stream_context_create($options);
$this->stream = @stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
if (false === $this->stream) {
throw new Swift_TransportException(
'Connection could not be established with host '.$this->params['host'].
' ['.$errstr.' #'.$errno.']'
);
}
嗯 是 stream_socket_client 这个函数没有正常运行。
查文档 php7.2到php7.3没有对这个函数进行更改。
那么问题出在哪呢。
将这段代码拎出来单独运行。
<?php
$a=stream_socket_client("ssl://smtp.exmail.qq.com:465", $errno, $errstr, 120, STREAM_CLIENT_CONNECT);
?>
错误出来了
Warning: stream_socket_client(): open_basedir restriction in effect. File(/etc/pki/tls/certs/ca-bundle.crt) is not within the allowed path(s): (/www/wwwroot/test.zhusutao.com/:/tmp/:/proc/) in /www/wwwroot/test.zhusutao.com/test.php on line 2
Warning: failed loading cafile stream: `/etc/pki/tls/certs/ca-bundle.crt' in /www/wwwroot/test.zhusutao.com/test.php on line 2
Warning: stream_socket_client(): Failed to enable crypto in /www/wwwroot/test.zhusutao.com/test.php on line 2
Warning: stream_socket_client(): unable to connect to ssl://smtp.exmail.qq.com:465 (Unknown error) in /www/wwwroot/test.zhusutao.com/test.php on line 2
说 open_basedir
没有包含 /etc/pki/tls/certs/ca-bundle.crt
那么包含进去吧。
发现还是不行。
看一下这个文件存在不 /etc/pki/tls/certs/ca-bundle.crt
嗯果然不存在。
看文件名像是证书文件。
比对一下php7.2的配置
嗯
php7.2 的配置
curl.cainfo = /etc/ca-bundle.crt
openssl.cafile = /etc/ca-bundle.crt
php7.3的配置
curl.cainfo = /etc/pki/tls/certs/ca-bundle.crt
openssl.cafile = /etc/pki/tls/certs/ca-bundle.crt
嗯 文件路径错误无疑了
改过来
php7.3新的的配置
curl.cainfo = /etc/ca-bundle.crt
openssl.cafile = /etc/ca-bundle.crt
在试着发送一下
完美!
Laravel 技术交流QQ群 852529151
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: