I’m trying to implement email functionality in my Symfony 5.1 application using Gmail’s SMTP service. When I attempt to send an email, I receive an error related to SSL certificate verification.
Here’s what I’ve configured:
mailer.yaml:
framework:
mailer:
dsn: '%env(MAILER_DSN)%'
In my .env file:
MAILER_DSN=gmail+smtp://[email protected]:mypassword@localhost
This is the error message I get:
Connection could not be established with host "ssl://smtp.gmail.com:465": stream_socket_client():
SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
I’ve made sure to turn on “Allow less secure apps” for my Gmail account, but I still face this verification issue. Can anyone suggest what might be wrong or how to fix this?
I encountered this exact issue last year when deploying a Symfony application to a server with outdated SSL certificates. The problem is likely with your MAILER_DSN configuration - you’re pointing to localhost instead of Gmail’s actual SMTP server. Try changing your .env file to:
MAILER_DSN=gmail+smtp://[email protected]:[email protected]:587
Note that I’m using port 587 with STARTTLS instead of 465 with SSL, which tends to be more reliable. Also, instead of enabling “less secure apps” (which Google is phasing out), consider generating an App Password from your Google Account settings. This approach resolved the certificate verification errors I was experiencing and is more secure than using your actual Gmail password.
This certificate verification failure often stems from PHP’s SSL context configuration rather than just the DSN setup. I ran into this same issue when migrating a legacy Symfony project and found that PHP was using strict SSL verification by default. You can try adding SSL context options to bypass the verification temporarily by modifying your mailer transport configuration. In your services.yaml, you might need to configure the transport with custom SSL options that disable peer verification. However, this is not recommended for production environments due to security implications. A better long-term solution is ensuring your server’s OpenSSL installation recognizes Gmail’s certificate authority. Check your PHP version as well - older PHP versions sometimes have compatibility issues with Gmail’s newer SSL certificates. If you’re still having trouble, consider switching to using Symfony’s native Gmail transport which handles these SSL nuances more gracefully.
had similiar problem few months ago. the ssl cert error usually happens when your system cant verify gmail’s certificate. try updating your ca-certificates bundle first with sudo apt-get update && sudo apt-get install ca-certificates
if on ubuntu. also make sure your php openssl extension is up to date - thats what fixed it for me.