From 819981708b8f89e2cef818905deb85fca4d630b4 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 4 Oct 2019 22:46:13 -0600 Subject: [PATCH] Make dynamic subjects available to mail templates Accomplishes this by firing the message callback before content is added to the message. This fixes an issue where subjects set on the message object through the callback were not able to override a mail template's subject as they're supposed to in System\Classes\MailManager because the callback was called after the MailManager's listener for mailer.beforeAddContent had already fired. The original issue was reported and fixed in octobercms/october#1665. However, that fix was then later broken by https://github.com/octobercms/library/commit/f409ad425e68e38adf8917f80769ea6af828f267 which was for the L5.5 upgrade in Build 420. It's also worth noting that Laravel has moved the callback to be before the content is added starting in L5.6, so this change also brings us closer in line with Laravel for the future 6.0 upgrade (see https://github.com/laravel/framework/pull/22995 for that commit and background information). --- src/Mail/Mailer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php index 61797f996..31995a530 100644 --- a/src/Mail/Mailer.php +++ b/src/Mail/Mailer.php @@ -66,6 +66,10 @@ public function send($view, array $data = [], $callback = null) $data['message'] = $message = $this->createMessage(); + if ($callback !== null) { + call_user_func($callback, $message); + } + if (is_bool($raw) && $raw === true) { $this->addContentRaw($message, $view, $plain); } @@ -73,10 +77,6 @@ public function send($view, array $data = [], $callback = null) $this->addContent($message, $view, $plain, $raw, $data); } - if ($callback !== null) { - call_user_func($callback, $message); - } - if (isset($this->to['address'])) { $this->setGlobalTo($message); }