简体   繁体   English

发送邮件Symfony2

[英]Send mailer Symfony2

I use Symfony2. 我使用Symfony2。 My Action send a message and then redirect to a page. 我的操作发送一条消息,然后重定向到页面。

Like this 像这样

public function myAction()
{
    ...
    some code 
    ...

    sendMessageWithSwiftMailer()
    ....

    return $this->redirect(Url);

}

This code work. 此代码有效。 But Url takes so much time to be opened. 但是Url需要花费很多时间才能打开。 How can I first open the Url page and then send the message? 如何首先打开“ Url页面,然后发送消息? Can anyone give me any idea? 谁能给我任何想法?

You can use: 您可以使用:

swiftmailer:
    spool: { type: file }

in your config_prod.yml and: 在您的config_prod.yml

swiftmailer:
    spool: { type: memory }

in your config.yml . 在您的config.yml

Then, in production environment, you can create a crontab job which executes this Symfony2 command: 然后,在生产环境中,您可以创建一个crontab作业来执行此Symfony2命令:

app/console swiftmailer:spool:send

This command will send your spooled messages. 此命令将发送假脱机消息。

More info at symfony.com/doc/current/cookbook/email/spool.html 有关更多信息,请访问symfony.com/doc/current/cookbook/email/spool.html

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

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