0
  • I got exception:

Connection could not be established with host smtp.gmail.com

  • Same exception in old project Symfony2.8 and newest Symfony3.
  • I can ping smtp.gmail.com.

enter image description here

user6827096
  • 1,186
  • 1
  • 11
  • 26

3 Answers3

2

The Avast Antivirus was guilty.

user6827096
  • 1,186
  • 1
  • 11
  • 26
0

In Google "Account settings" enable "Access for less secured apps" by setting it to "Allow".

Mailer host is your localhost or 127.0.0.1. It's not smtp.google.com

Manoj Kumar
  • 440
  • 1
  • 4
  • 21
0

I'm using this configuration for my localhost application

parameters:
    mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: youremail@gmail.com //replace by your gmail account
    mailer_password: ********** //replace by your gmail password

config.yml:
    swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

your controller code seems to be the same as mine.

As napestershine said in his response do not forget to allow less secure app on your gmail account.

Mz1907
  • 625
  • 4
  • 10