Example #1
0
 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);
 }
Example #2
0
 /**
  * Returns true if the template is still fresh.
  *
  * @param string $name The template name
  * @param int    $time The last modification time of the cached template
  *
  * @return Boolean true if the template is fresh, false otherwise
  *
  * @throws Twig_Error_Loader When $name is not found
  */
 public function isFresh($name, $time)
 {
     $info = $this->cr->getInfo($this->getFile($name));
     return $info->getLastModified()->getTimestamp() > $time;
 }