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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With