Troubleshooting Symfony mailer configuration with Gmail SMTP

Hey everyone,

I’m having some trouble setting up the Symfony mailer with Gmail in my Symfony 5.1 project. I’ve configured it as follows:

In mailer.yaml:

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

And in .env:

MAILER_DSN=gmail+smtp://[email protected]:mypassword@localhost

However, when I try to send an email, I get this error:

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 already enabled less secure app access in my Gmail account, but it’s still not working. The Symfony docs suggest this setup should work fine. Any ideas what I might be missing or doing wrong? Thanks in advance for any help!

I encountered a similar issue when configuring Symfony mailer with Gmail. The problem might be related to SSL certificate verification. Try modifying your MAILER_DSN in the .env file to disable SSL verification:

MAILER_DSN=gmail+smtp://[email protected]:mypassword@default?verify_peer=0

This isn’t ideal for production, but it can help isolate the issue. If it works, you’ll need to update your SSL certificates or configure Symfony to use a custom CA bundle.

Also, ensure you’re using an app password instead of your regular Gmail password. You can generate one in your Google Account settings under ‘Security’ > ‘App passwords’. This is more secure and often resolves authentication issues.

hey there! i’ve run into this before. make sure you’ve got the latest ca-certificates installed on ur server. Also, double-check that ur using the right port (465 for SSL or 587 for TLS). if that doesnt work, try using the full gmail smtp address in ur DSN. Good luck!