Symfony + Swiftmailer,它不发送电子邮件

Symfony + Switfmailer, It doesnt send emails

我正在尝试使用 FOSUserBundle 在我的网络应用程序中发送电子邮件。

当我注册一个新用户时,会显示一条来自 FOSUserBundle 的闪现消息(电子邮件已成功发送),但是当我检查调试工具栏时:

未收到电子邮件:

Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com

有人可以帮我吗?

我的配置是config.yml:

#Swiftmailer Configuration
swiftmailer:
    transport:  "%mailer_transport%"
    username:   "%mailer_user%"
    password:   "%mailer_password%"
    spool:      { type: memory }

#FOSUser
fos_user:
    from_email:
        address:     "%mailer_user%"
        sender_name: "%mailer_user%"

    registration:
        confirmation:
            enabled: true

我的parameters.yml是:

parameters:
    # ...Database config...

    mailer_transport: gmail
    mailer_user: nick@gmail.com
    mailer_password: pass
    secret: ThisTokenIsNotSoSecretChangeIt

备注:

  • I have activated "Allow or prevent less secure applications from accessing accounts" on Gmail.

  • I assumed SwitfMailer is included in the installation of Symfony in 3.4 version.

在互联网和此处寻找解决方案很长时间后,这对我有用 config.yml:

  swiftmailer:
    transport: "%mailer_transport%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    stream_options:
        ssl:
            allow_self_signed: true
            verify_peer: false
            verify_peer_name: false
    spool:     { type: memory }

PD:不建议在生产环境中使用此解决方案。