/** * Compose the email data to be sent. * * @param FormConfig $formConfig * @param EmailConfig $emailConfig * @param FormData $formData */ private function emailCompose(FormConfig $formConfig, EmailConfig $emailConfig, FormData $formData) { /* * Create message object */ $this->message = \Swift_Message::newInstance(); $this->message->setEncoder(\Swift_Encoding::get8BitEncoding()); // Set our Twig lookup path $this->addTwigPath(); // If the form has it's own templates defined, use those, else the globals. $templateSubject = $formConfig->getTemplates()->getSubject() ?: $this->config['templates']['subject']; $templateEmail = $formConfig->getTemplates()->getEmail() ?: $this->config['templates']['email']; $fieldmap = $this->config['fieldmap']['email']; /* * Subject */ $html = $this->app['render']->render($templateSubject, array($fieldmap['subject'] => $formConfig->getNotification()->getSubject(), $fieldmap['config'] => $emailConfig, $fieldmap['data'] => $formData)); $subject = new \Twig_Markup($html, 'UTF-8'); /* * Body */ $html = $this->app['render']->render($templateEmail, array($fieldmap['fields'] => $formConfig->getFields(), $fieldmap['config'] => $emailConfig, $fieldmap['data'] => $this->getBodyData($emailConfig, $formData))); $body = new \Twig_Markup($html, 'UTF-8'); $text = preg_replace('/<style\\b[^>]*>(.*?)<\\/style>/s', '', $body); /* * Build email */ $this->message->setSubject($subject)->setBody(strip_tags($text))->addPart($body, 'text/html'); }