swift mailer send to queue for later delivery
Asked Answered
I

3

9

When using http://swiftmailer.org can I send a message to the mail queue so that php returns right away instead of actually sending the message right now?

Inez answered 27/1, 2012 at 20:26 Comment(0)
R
7

This is an old question, but since it came up in my google search, I'll answer it with what I figured out.

YES! Swiftmailer has the ability to write to a spool instead of sending immediately. Implementation is pretty easy:

$spool = new Swift_FileSpool('/where/you/want/your/spool');
$transport = Swift_SpoolTransport::newInstance($spool);
$mailer = Swift_Mailer::newInstance($transport);

This tells swiftmailer to write messages to the disk rather then send them. Then using a cron job or other trigger send the messages using something like:

$spool = new Swift_FileSpool('/where/you/put/your/spool');
$spool_transport = Swift_SpoolTransport::newInstance($spool);

// Create the smtp transport.

$smtp_transport = Swift_SmtpTransport::newInstance('your.smtp.host', 25);

// Get the messages from the spool
$spool = $spool_transport->getSpool();

// Send the messages via the real transport.
$sent = $spool->flushQueue($smtp_transport);
Rociorock answered 13/10, 2016 at 16:38 Comment(0)
S
1

You can't. swiftmailer/php don't actually deliver the mail for you, they just hand it over to the SMTP server, and THAT server does the delivery for you. You'd need to tell the SMTP to not process the outgoing queue to 'stop' delivery.

In realworld terms, swift/php just walk to the corner and drop your envelope in the mail box. The postal truck shows up immediately afterwards and starts the process of sending the mail on its way through the postal system. But that's completely out of PHP's purview.

Semang answered 27/1, 2012 at 20:28 Comment(1)
What if I'm using sendmail as the transport? (Swift_SendmailTransport)Inez
D
0

If you are using the sendmail transport then it should return right away.

From https://github.com/swiftmailer/swiftmailer/blob/4.1/doc/sending.rst :

Usually the sendmail process will respond quickly as it spools your messages to disk before sending them.

You can also have a look at spooling: http://symfony.com/doc/current/cookbook/email/spool.html

Devoir answered 17/6, 2012 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.