2

I have a web application made with Symfony 2.4 and I use SwiftMailer to send emails.

I use like mailer transport sendmail.

When user send an email, I don't receive this email. But If I do in command line:

$php app/console swiftmailer:spool:send --env=prod

I receive all emails.

¿What can I do?

Thanks a lot!

----Edit----

I have removed all references to spool in my config file, but the problem persist.

----Edit 2----

Config.yml

mailer_transport: sendmail
mailer_host: ****
mailer_user: *****
mailer_password: ****
user2794692
  • 361
  • 2
  • 10
  • 24

1 Answers1

2

Delete the spool line from your configuration (parameters.yml i believe? I've never used symfony so i'm interpreting the docs).

Once you've deleted any mention of the spool from your config, it should stop spooling and send immediately.

Having said that, the reason for spooling is so that it sends the email at the end of the execution of the request so that you don't have the performance hit (slowed down requests), probably via a shutdown function... the only reason this function wouldn't execute and therefore your email's not send, is if the script is ending early (i.e. a die/exit or uncatched exception), so you may want to look at addressing the root cause rather than patching around it.

Edit: manual flush (fund this on a command line script example, i've edited it to what i think should make it work for you....)

// now manually flush the queue
$container = $this->getContainer();
$mailer = $this->get('mailer');
$spool = $mailer->getTransport()->getSpool();
$transport = $container->get('swiftmailer.transport.real');

$spool->flushQueue($transport);

http://symfony.com/doc/current/cookbook/console/sending_emails.html

Lee
  • 10,496
  • 4
  • 37
  • 45
  • Thanks, but I have removed all references about spool in my config file and emails doesn't send – user2794692 Jan 23 '14 at 10:13
  • Can you check they aren't still spooling by running that send command via the command line. After running that command, if you then get an email, they are still spooling and we need to work out why – Lee Jan 23 '14 at 10:42
  • When I use the command line I receive all the emails stored in spool. Then, If another user send me an email, this again is stored in spool and I need to run the command line again. – user2794692 Jan 23 '14 at 10:45
  • Right if that's still happening, then your still spooling, which is the problem. Can you post your parameters config file? Maybe trim out anything you don't want public to see (url's, password, whatever). Also it may be worth making sure you have full error reporting enabled, so you can work out why the spool isn't flushing automatically at the end of execution – Lee Jan 23 '14 at 10:48
  • The problem is emails are stored in spool but I never receive this messages in my email, I need to run the command line to get this. I edit the first post with the config. – user2794692 Jan 23 '14 at 10:54
  • Yep i know the problem and i've explained why. It's either a config issue or an error thats causing it not to flush the spool (hence why is aid enable all error reporting). There's supposedly an `app/config/parameters.yml` file too, where most of the email config goes (according to one blog post ive read). Have you checked for that file and ensured no spool config in there? If you have checked, then see my edit above, i think you can manually flush it from the script too – Lee Jan 23 '14 at 10:57
  • Thanks, I test this, but I get 503 Service Unavailable – user2794692 Jan 23 '14 at 11:03
  • Unfortunately i think i've exhausted my googling ability. Without access to the code and an understanding of symfony, i can't help you any further. I would recommend enabling error reporting both in symfony and php itself (ask google how to), and working out what the errors are which are causing your issues, Symfony is mature enough by now to have had any serious email issues squashed by now, so it's definitely something you've done which is causing the issue. You'll just have to go through the usual debug steps – Lee Jan 23 '14 at 11:13
  • FYI I solved this issue with a crontab process, isn't cool solution but works fine :) – user2794692 Jan 23 '14 at 11:32