I am using Laravel 4.2, which uses the swiftmailer lib for email. I am trying to use the Sendgrid SMTP service but I am getting an timeout error on my staging server.
Everything works fine in my local development.
mail.php
return array(
'driver' => 'smtp',
'host' => 'smtp.sendgrid.net',
'port' => 587,
'encryption' => 'tls',
'username' => 'username'
'password' => ...
I have switching to port 465 and 'ssl', works on the local but no luck on the server. OpenSSL is enabled on the server.
What is interesting is Mandrill smtp (this uses a different laravel driver) and the local server smtp work fine on the server.
The ports are open. I can telnet into sendgrid from the server. I also switched out the host name for the IPv4 just to checks because of all of the trouble people have with using smtp.gmail.com IPv4 vs IPv6. Didn't make a difference.
The specific error location is this:
$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.']');
So my question is what should I check to figure out why swiftmailer and the stream_socket_client php function is working locally but not on the server. Locally I am on a mac, the server is running centOS.