我使用的是Laravel 4.2,它使用电子邮件的swiftmailer库。我正在尝试使用Sendgrid SMTP服务,但我的临时服务器上出现超时错误。
在我当地的发展中一切都很顺利
mail.php
return array(
'driver' => 'smtp',
'host' => 'smtp.sendgrid.net',
'port' => 587,
'encryption' => 'tls',
'username' => 'username'
'password' => ...
我已经切换到端口465和"ssl",在本地工作,但在服务器上没有运气。服务器上已启用OpenSSL。
有趣的是Mandrill smtp(这使用了不同的laravel驱动程序)和本地服务器smtp在服务器上运行良好。
端口是打开的。我可以从服务器远程登录到sendgrid。我还切换了IPv4的主机名,只是为了检查一下,因为人们在使用smtp.gmail.com IPv4与IPv6时遇到了很多麻烦。没什么区别。
具体错误位置如下:
$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.']');
因此,我的问题是,我应该检查什么来弄清楚为什么swiftmailer和stream_socket_client.php函数在本地工作,但在服务器上不工作。在本地,我在mac上,服务器正在运行centOS。
看起来应用程序是由无法访问端口587的用户运行的。因此,如果遇到这个问题,请确保您正在与运行应用程序的用户一起测试端口。