Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is because the <code>SwiftmailerServiceProvider</code> uses a <code>Swift_MemorySpool</code> by default, and only flushes that on <code>kernel.terminate</code>. Let me take a step back and explain each part of this.</p> <ul> <li><p>The <code>SwiftmailerServiceProvider</code> is responsible for registering the Swiftmailer services and default configuration. By default the transport (<code>swiftmailer.spooltransport</code>) is <code>Swift_SpoolTransport</code> and the <code>swiftmailer.spool</code> is <code>Swift_MemorySpool</code>.</p></li> <li><p>Swiftmailer supports different ways of sending the mails. These are called transports. The spool transport acts as a queue. You can either store this queue in a file or in memory. Spool transports have a <code>flushQueue</code> method which allows flushing the queued mails to a real transport, which should deliver them.</p></li> <li><p>The Symfony2 HttpKernel which Silex uses emits a number of events during the lifecycle of every request. The last one that it emits is the <code>kernel.terminate</code> event. This event is triggered after the HTTP response body has been sent. This allows you to do heavy tasks after rendering the page, so that it no longer appears as loading to the user.</p></li> <li><p>The <code>SwiftmailerServiceProvider</code> subscribes to the <code>kernel.terminate</code> event in order to flush the memory spool after the page has been rendered. It flushes it to <code>swiftmailer.transport</code> service, which is a <code>Swift_Transport_EsmtpTransport</code> that does the actual sending via SMTP.</p></li> </ul> <p>So let's get to the actual problem. You are in a CLI context, so none of those HttpKernel events will be fired. And since the <code>kernel.terminate</code> event is not fired, your spool is not being flushed. And thus your emails are not getting sent.</p> <p>There's two good solutions for this:</p> <ul> <li><p>A) Flush the spool manually. Just do what the provider does in its listener. Add this at the end of your CLI command:</p> <pre><code>if ($app['mailer.initialized']) { $app['swiftmailer.spooltransport']-&gt;getSpool()-&gt;flushQueue($app['swiftmailer.transport']); } </code></pre></li> <li><p>B) Re-configure the <code>mailer</code> service to use the ESMTP transport directly without going through the spool:</p> <pre><code>$app['mailer'] = $app-&gt;share(function ($app) { return new \Swift_Mailer($app['swiftmailer.transport']); }); </code></pre></li> </ul> <p>Either solution should do. Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload