diff --git a/src/MailSender.php b/src/MailSender.php index cae849a..0b09826 100644 --- a/src/MailSender.php +++ b/src/MailSender.php @@ -29,7 +29,7 @@ public function send($name, array $context = []) $template = $this->twig->loadTemplate($name); $blocks = []; - foreach (['from', 'to', 'subject', 'body_txt', 'body_html'] as $blockName) { + foreach (['from', 'from_name', 'to', 'to_name', 'subject', 'body_txt', 'body_html'] as $blockName) { $rendered = $this->renderBlock($template, $blockName, $context); if ($rendered) { @@ -41,10 +41,10 @@ public function send($name, array $context = []) $mail = new \Swift_Message(); $mail->setSubject($blocks['subject']); - $mail->setFrom($blocks['from']); + $mail->setFrom(isset($blocks['from_name']) ? [$blocks['from'] => $blocks['from_name']] : $blocks['from']); if (isset($blocks['to'])) { - $mail->setTo($blocks['to']); + $mail->setTo(isset($blocks['to_name']) ? [$blocks['to'] => $blocks['to_name']] : $blocks['to']); } if (isset($blocks['body_txt']) && isset($blocks['body_html'])) {