I’m trying to send emails using Laravel’s Mail facade with Gmail SMTP on a cPanel server. While the configuration works perfectly on my local environment, on the server I’m encountering two different issues:
- Timeout errors when trying to connect to Gmail’s SMTP server
- SSL certificate verification failures
These issues persist despite successful SSL and port tests. I’ve confirmed that basic connectivity works:
- Port tests succeed (connection establishes in 71ms)
- OpenSSL tests show successful TLS negotiation
- Server can reach Gmail SMTP servers
I’ve tried multiple configuration approaches including:
- Using both SSL (465) and TLS (587) ports
- Different encryption methods (SSL/TLS)
- Various SSL verification settings
- Different SMTP hosts (smtp.gmail.com and smtp-relay.gmail.com)
- Adjusting timeout values
- Different authentication modes
Each attempt results in either a timeout or an SSL certificate verification error, even though the same configuration works flawlessly in the local environment.
Environment:
- Laravel version 11.34.2
- PHP 8.2.25
- cPanel server
- Gmail SMTP
Configuration Working on Local:
'smtp' => [
'transport' => 'smtp',
'url' => null,
'host' => 'smtp.gmail.com',
'port' => 587,
'encryption' => 'tsl',
'username' => '[email protected]',
'password' => "app-password",
'timeout' => null,
],
Error #1 – Timeout:
Error sending: SMTP Error: Could not connect to SMTP host.
Configuration USED:
'smtp' => [
'transport' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'encryption' => 'ssl',
'username' => '[email protected]',
'password' => 'app-password',
'timeout' => 5,
'stream_options' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
]
]
],
Error #2 – SSL Certificate:
Error sending: SMTP Error: Could not connect to SMTP host.
Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Configuration USED:
'smtp' => [
'transport' => 'smtp',
'host' => 'smtp-relay.gmail.com',
'port' => 587,
'encryption' => 'tls',
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => 5,
'auth_mode' => 'PLAIN',
'stream_options' => [
'tcp' => [
'tcp_nodelay' => true,
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
'SNI_enabled' => true,
]
]
],
- Port tests show successful connections:
$ time nc -zv -w 5 smtp.gmail.com 465
Connection to smtp.gmail.com 465 port [tcp/submissions] succeeded!
real 0m0.071s
- OpenSSL test shows successful TLS negotiation:
$ openssl s_client -connect smtp.gmail.com:465
...
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
...
220-smtp.gmail.com ESMTP ready
- Verified Exim settings:
$ sudo exim -bP accept_8bitmime
accept_8bitmime
$ sudo exim -bP smtp_accept_max_nonmail
smtp_accept_max_nonmail = 10
- Tried both SSL (465) and TLS (587) ports
- Tried different timeout values
- Verified Gmail app password and 2FA settings
- Added various SSL/TLS configurations and certificate verifications
- Tried using smtp-relay.gmail.com
The connection tests succeed but Laravel’s mailer consistently times out. The quick netcat connection (71ms) suggests the issue might be during SSL handshake or SMTP authentication, but I haven’t been able to resolve it.
Any help would be appreciated.
Helia Haghighi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3