Trying to send email with Swiftmailer, I got this error. I’ve configured swiftmailer with:
transport: smtp host: smtp.gmail.com username: firstname.lastname@example.org password: password port: 587 encryption: ssl
I always get this error message:
Connection could not be established with host smtp.gmail.com
I’ve also tried with:
transport: gmail host: smtp.gmail.com username: email@example.com password: password port: 587 encryption: ssl
The complete error message is
[YYYY-mm-dd hh:ii:ss] app.ERROR: Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com [ #0]
My case is different from this. In my case I’ve not Avast antivirus.
EDIT: changing port to 465, as Alex Howansky suggested, erro changes in
Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username “my email address” using 1 possible authenticators
1: Either you must allow less secure apps or use app password by enabling 2 step verification on your gmail acc.
2: Disable any antivirus on your machine(this is something no one will tell u but is necessary in many cases).
3: Don’t forget to clear your cache (sometimes it don’t take updated content from .env file)
4: You don’t need to change anything in Mailer inside config directory(not recommended), you should use env variables
it’s looking for the server smtp.gmail.com but isn’t able to resolve it. use this domain smtp.gmail.com and port 25 or 465.