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?
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);
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.
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
© 2022 - 2024 — McMap. All rights reserved.