mailer = $mailer; $this->router = $router; $this->twig = $twig; $this->parameters = $parameters; } /** * @param string $templateName * @param array $context * @param array $fromEmail * @param string $toEmail */ protected function sendMessage($templateName, $context, $fromEmail, $toEmail) { $template = $this->twig->load($templateName); $subject = $template->renderBlock('subject', $context); $textBody = $template->renderBlock('body_text', $context); $htmlBody = ''; if ($template->hasBlock('body_html', $context)) { $htmlBody = $template->renderBlock('body_html', $context); } $email = (new Email()) ->from(new Address(key($fromEmail), current($fromEmail))) ->to($toEmail) ->subject($subject); if (!empty($htmlBody)) { $email ->text($textBody) ->html($htmlBody); } else { $email->text($textBody); } $this->mailer->send($email); } }