Search code examples
phpemailsymfonyproduction-environmentswiftmailer

Symfony swiftmailer in production environment


I have a problem for sending mails with Swiftmailer in Symfony2. Let me explain it: when I go to my website with the app_dev.php, I could send messages, there is no problem (also, when I write $kernel = new AppKernel('prod', true); in app.php).

So, I don't understand why this works in dev and not in prod.

Here is my configuration files:

parameters.yml:

mailer_transport: smtp
mailer_host: ****.ovh.net
mailer_username: postmaster@mywebsite.com
mailer_password: ****
mailer_port: ****

config.yml:

swiftmailer:
transport: "%mailer_transport%"
host:      "%mailer_host%"
username:  "%mailer_username%"
password:  "%mailer_password%"
port:      "%mailer_port%"
spool:     { type: memory }

And this is the php code, but I think there is no problem with it because as I said there is no problem in dev mode.

$message = \Swift_Message::newInstance() -> setSubject('Test')
         -> setFrom('postmaster@mywebsite.com')
         -> setTo($user -> getMail())
         -> setBody('Test');
$this -> get('mailer') -> send($message);

Thank you very much if you know where is the problem.


Solution

  • If something worked in dev, but not prod try manually deleting the prod cache directory and re-installing and dumping assets again. Review this checklist from the docs.