简体   繁体   English

symfony2:不发送电子邮件

[英]symfony2: emails are not sent

  $mail = \Swift_Message::newInstance()
            ->setSubject($message->getSubject())
            ->setFrom($message->getEmail())
            ->setBody($message->getBody());

        $this->get('mailer')->send($mail);

Mails are not sent when using swiftmailer. 使用swiftmailer时不会发送邮件。 Yet, when I go step by step in the debugger, it seems to send the email and returns sent=1. 然而,当我一步一步地进入调试器时,它似乎发送了电子邮件并返回sent = 1。 However I don't receive anything in my mailbox (gmail). 但是我的邮箱(gmail)中没有收到任何内容。 I use my gmail account for sending emails, as shown below: 我使用我的Gmail帐户发送电子邮件,如下所示:

parameters:
mailer_transport: gmail
mailer_host: ~ 
mailer_user: username@gmail.com
mailer_password: my-password
delivery_address: username@gmail.com



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

I've checked apache error log, nothing. 我已经检查了apache错误日志,没有。 I've run php app/console swiftmailer:spool:send just in case, but no luck. 我运行php app/console swiftmailer:spool:send以防万一,但没有运气。

What could prevent emails from being sent ? 什么可以阻止发送电子邮件?

You need either to: 您需要:

1) Remove the spool line in your swiftmailer configuration, this one: 1)删除swiftmailer配置中的假脱机行,这一行:

spool: { type: memory } spool:{type:memory}

2) Trigger the spool queue to be sent: 2)触发要发送的假脱机队列:

php app/console swiftmailer:spool:send php app / console swiftmailer:spool:send

But I think you are looking for option 1) 但我认为你正在寻找选项1)

u can try this one... 你可以尝试一下......

Parameter.yml Parameter.yml

mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'xxxxxxxxxxxx'

config.yml config.yml

    swiftmailer:
       transport: gmail
       host:      smtp.gmail.com
       username:  'Yourmail-id@gmail.com'
       password:  'Password'

The ->setTo part was missing ! - > setTo部分丢失了! That solved it. 这解决了它。

  $mail = \Swift_Message::newInstance()
            ->setSubject($message->getSubject())
            ->setFrom($message->getEmail())
            ->setTo("me@gmail.com")
            ->setBody($message->getBody());

First, when you set spool: { type: memory } it means that you actually want to send the emails manually by running the spool command: php app/console swiftmailer:spool:send . 首先,当你设置spool: { type: memory }它意味着你真的想通过运行spool命令手动发送电子邮件: php app/console swiftmailer:spool:send So removing that spool line is going to help. 因此删除该线轴将有所帮助。

Second, you need to properly configure your mailing host. 其次,您需要正确配置邮件主机。 For development purposes, I strongly recommend that you use a service such as SendGrid and configure it as detailed in this Symfony2 Mailing Setup Tutorial 出于开发目的,我强烈建议您使用SendGrid等服务并按照此Symfony2邮件设置教程中的详细说明对其进行配置

The tutorial also contains details on how to properly setup a mailing service in Symfony2 and how to build mailing templates. 本教程还包含有关如何在Symfony2中正确设置邮件服务以及如何构建邮件模板的详细信息。

Third, if you want to stick with Gmail, then the correct data is: 第三,如果你想坚持使用Gmail,那么正确的数据是:

mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: your_gmail_address@gmail.com
mailer_password: 'your_gmail_password'
mailer_port: 587

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM