title: Symfony2 and FOSUserBundle : Override Mailer
body: <p>i come here because i have a problem with OVH and my symfony2 application, i can't send mail with SwiftMailer. It's rather problematic for FOSUserBundle to reset the password or activate my account after inscription. So i want to use the <code>MAIL</code> function implemented in PHP, i followed the documentation <a href="https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/emails.md" rel="nofollow">here</a> . So i created my class <code>MailerInterface.php</code>and the class <code>Mailer.php</code> because this class send the mail with the function <code>sendEmailMessage</code></p>
  
  <p>Here, you can see how i implemented the class :</p>
  
  <pre><code>&lt;?php
        namespace MonApp\UserBundle\Mailer;
  
        use FOS\UserBundle\Model\UserInterface;
  
        interface MailerInterface
        {
             function sendConfirmationEmailMessage(UserInterface $user);
  
             function sendResettingEmailMessage(UserInterface $user);
        }
  ?&gt;
  </code></pre>
  
  <p>And the <code>Mailer.php</code> :</p>
  
  <pre><code>&lt;?php
        namespace MonApp\UserBundle\Mailer;
  
        use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
        use Symfony\Component\Routing\RouterInterface;
        use FOS\UserBundle\Model\UserInterface;
        use MonApp\UserBundle\Mailer\MailerInterface;
  
        class Mailer implements MailerInterface
        {
            protected $mailerMonApp;
            protected $router;
            protected $templating;
            protected $parameters;
  
            public function __construct($mailerMonApp, RouterInterface $router, EngineInterface $templating, array $parameters) {
                 $this-&gt;mailerMonApp = $mailerMonApp;
                 $this-&gt;router = $router;
                 $this-&gt;templating = $templating;
                 $this-&gt;parameters = $parameters;
            }
  
            public function sendConfirmationEmailMessage(UserInterface $user) {
                 The function...
            }
  
            public function sendResettingEmailMessage(UserInterface $user) {
                 The function...
            }
  
            protected function sendEmailMessage($renderedTemplate, $fromEmail, $toEmail) {
                $renderedLines = explode("\n", trim($renderedTemplate));
                $subject = $renderedLines[0];
                $body = implode("\n", array_slice($renderedLines, 1));
  
                mail($toEmail, $subject, $body, 'noreply@nondedomaine.fr');
            }
       }
  </code></pre>
  
  <p>I added my class as service :</p>
  
  <pre><code>services:
       monapp.mailer:
            class: MonApp\UserBundle\Mailer\Mailer
  </code></pre>
  
  <p>And changed the <code>config.yml</code> :</p>
  
  <pre><code>service:
      mailer: monapp.mailer
  </code></pre>
  
  <p>Here the <code>ERROR</code> in Dev env :</p>
  
  <pre><code>     Warning: Missing argument 1 for MonApp\UserBundle\Mailer\Mailer::__construct(), called in /home/domaine/www/nomappli/app/cache/dev/appDevDebugProjectContainer.php on line 831 and defined in /home/domaine/www/nomappli/src/MonApp/UserBundle/Mailer/Mailer.php line 29
  </code></pre>
  
  <p>My problem is : When i arrive on my reset password page, i write my pseudo and after validation of the form i got a white page. I think i call the <code>class and use</code> used in the tutorial so i don't understand my problem, maybe i forgot a use ?</p>
  
  <p>Thanks</p>
  
  <p><strong><em>EDIT</em></strong>
  Here the logs errors (Thanks to Michael &amp; Yann for helped me) :</p>
  
  <pre><code>[2015-03-31 14:55:35] request.INFO: Matched route "fos_user_resetting_send_email" (parameters: "_controller": "FOS\UserBundle\Controller\ResettingController::sendEmailAction", "_route": "fos_user_resetting_send_email") [] []
  [2015-03-31 14:55:35] security.INFO: Populated SecurityContext with an anonymous Token [] []
  [2015-03-31 14:55:35] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Unable to find template ""." at /home/nomappli/www/monapp/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 {"exception":"[object] (InvalidArgumentException: Unable to find template \"\". at /home/nomappli/www/monapp/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php:128, Twig_Error_Loader: Unable to find template \"\". at /home/nomappli/www/monapp/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php:106, InvalidArgumentException: Template name \"\" is not valid (format is \"bundle:section:template.format.engine\"). at /home/nomappli/www/monapp/app/cache/prod/classes.php:742)"} []
  [2015-03-31 14:55:35] security.DEBUG: Write SecurityContext in the session [] []
  </code></pre>