背景,laravel5.5开发网页部署到阿里云虚拟机上,用户注册时发送验证邮件出现以上报错,搜遍全网没找到解决方法,以下是解决步骤:
1)laravel中使用switchmailer框架发送邮件,该框架默认使用 stream_socket_client函数发送邮件,虚拟主机或轻云服务器禁用了此函数。 所以无法直接使用 switchmailer发送邮件。 可以通过修改默认的 switchmailer发送邮件的方式,实现使用 switchmailer发送邮件的功能。
2)找到报错位置vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php大概270行
$this->stream = @stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext)
修改为
$this->stream = @fsockopen($host, $this->params['port'], $errno, $errstr, $timeout)
3)由于虚拟主机或轻云服务器禁用了25号端口,邮件发送需要使用ssl465端口
4)前往虚拟主机后台php.ini设置打开fsockopen函数
至此,问题解决,如果帮助到你,给我点个赞!