Swift_TransportException·无法与主机smtp.sendgrid.net建立连接[连接超时#110]

时间:2015-12-16 15:55:23

标签: php email swiftmailer sendgrid

我正在使用Laravel 4.2,它使用swiftmailer lib来发送电子邮件。我正在尝试使用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在服务器上正常工作。

港口是开放的。我可以从服务器telnet到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。

1 个答案:

答案 0 :(得分:6)

看起来用户正在运行应用程序而无法访问端口587.因此,如果您遇到此问题,请确保您正在使用运行应用程序的用户测试端口。

相关问题