diff --git a/classes/mail/Mailable.php b/classes/mail/Mailable.php index 6e672421552..51c8373a287 100644 --- a/classes/mail/Mailable.php +++ b/classes/mail/Mailable.php @@ -121,6 +121,9 @@ class Mailable extends IlluminateMailable /** @var string embedded footer of the email */ protected string $footer; + /** @var bool define if email data has been set */ + protected bool $isDataSet = false; + public function __construct(array $variables = []) { if (!empty($variables)) { @@ -236,6 +239,16 @@ public function setData(?string $locale = null): void } $this->addFooter($locale); // set the locale for the email footer + + $this->isDataSet = true; + } + + /** + * return if the data for this email has been set + */ + public function hasDataSet(): bool + { + return $this->isDataSet; } /** @@ -492,6 +505,7 @@ protected static function getTypeNames(ReflectionType $type): array } $isUnion = $type instanceof ReflectionUnionType; if ($isUnion || $type instanceof ReflectionIntersectionType) { + /** @var ReflectionIntersectionType $type */ $flattenTypes = collect($type->getTypes()) ->map(fn ($type) => static::getTypeNames($type)) ->flatten(); diff --git a/classes/mail/Mailer.php b/classes/mail/Mailer.php index 4775c418abd..7ee6a96f266 100644 --- a/classes/mail/Mailer.php +++ b/classes/mail/Mailer.php @@ -115,7 +115,9 @@ public function send($view, array $data = [], $callback = null) { if (is_a($view, Mailable::class)) { /** @var Mailable $view */ - $view->setData(); + if (!$view->hasDataSet()) { + $view->setData(); + } } // Application is set to sandbox mode and will sent any emails to log