“Connection could not be established with host smtp.gmail.com”. Symfony. Swiftmailer

我是研究僧i 提交于 2019-12-13 07:01:58

问题


  • 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.


回答1:


The Avast Antivirus was guilty.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/40058392/connection-could-not-be-established-with-host-smtp-gmail-com-symfony-swiftma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!