问题
I need to use the spool option to send massive emails to my users, but i won't to change whole config of my app to spool because my register system send an email to the user and i want that this email be instant send.
Is any way to do this without change the global config for swiftmailer?
回答1:
You can configure different emailers. For example:
swiftmailer:
default_mailer: spool_mailer
mailers:
spool_mailer:
spool:
type: file
path: /path/to/spool
# ...
instant_mailer:
# ...
Then use one emailer or the other depending on whether you want to spool or not:
//in your controller
$spoolMailer = $this->get('swiftmailer.mailer.spool_mailer');
$spoolMailer->send(...); //this will be spooled
$instantMailer = $this->get('swiftmailer.mailer.instant_mailer');
$instantMailer->send(...); //this will be sent instantly
来源:https://stackoverflow.com/questions/33396773/send-emails-via-memory-in-controllers-and-spool-in-some-commands-in-symfony2