mailer = $mailer; $this->twig = $twig; $this->senderEmail = $senderEmail; $this->senderName = $senderName; $this->supportUrl = $supportUrl; $this->wallabagUrl = $wallabagUrl; } /** * Send the auth code to the user via email. * * @param TwoFactorInterface $user */ public function sendAuthCode(TwoFactorInterface $user) { $template = $this->twig->loadTemplate('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig'); $subject = $template->renderBlock('subject', array()); $bodyHtml = $template->renderBlock('body_html', [ 'user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl, 'wallabag_url' => $this->wallabagUrl, ]); $bodyText = $template->renderBlock('body_text', [ 'user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl, ]); $message = new \Swift_Message(); $message ->setTo($user->getEmail()) ->setFrom($this->senderEmail, $this->senderName) ->setSubject($subject) ->setBody($bodyText, 'text/plain') ->addPart($bodyHtml, 'text/html') ; $this->mailer->send($message); } }