public function sendTemplateMail(SendTemplateMailCommand $command) { $message = \Swift_Message::newInstance(); $ext = $command->format === 'text/html' ? 'html' : 'txt'; $tplIdentifier = 'Email/' . $command->template . '.' . $ext; $template = $this->cr->getContent($tplIdentifier); $templateData = $command->templateData; if ($command->image !== null) { $templateData['image'] = $message->embed(\Swift_Image::fromPath($command->image)); } // Subject $env = new \Twig_Environment(new \Twig_Loader_String()); $subject = $template->getProperties()->containsKey('subject') ? $template->getProperties()->get('subject') : $this->mailFromName; $subject = $env->render($subject, $templateData); // Body $body = $this->templating->render('bcrm_content:' . $tplIdentifier, $templateData); $message->setCharset('UTF-8'); $message->setFrom($this->mailFromEmail, $this->mailFromName)->setSubject($subject)->setTo($command->email)->setBody($body, $command->format); $this->mailer->send($message); }
/** * Gets the source code of a template, given its name. * * @param string $name The name of the template to load * * @return string The template source code * * @throws Twig_Error_Loader When $name is not found */ public function getSource($name) { $template = $this->cr->getContent($this->getFile($name)); return $template->getContent(); }