From 914ad595f08b2725f42f0e21decf50da4dc342df Mon Sep 17 00:00:00 2001 From: Tony Air Date: Fri, 29 Mar 2024 18:39:06 +0200 Subject: [PATCH] FIX: outdated swift mailer breaking mails formating --- src/MailerFix.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/MailerFix.php b/src/MailerFix.php index 0fe0d1c..b00d744 100644 --- a/src/MailerFix.php +++ b/src/MailerFix.php @@ -26,17 +26,43 @@ class MailerFix extends Email parent::__construct($from, $to, $subject, $body, $cc, $bcc, $returnPath); } - private static function convertVars($mails) { return is_array($mails) ? implode(' ', $mails) : $mails; } + private function loadDetails() + { + $fields = [ + 'From', + 'To', + 'Subject', + 'Body', + 'CC', + 'BCC', + 'ReturnPath', + ]; + + $i = 0; + foreach ($fields as $f) { + $func = 'get'.$f; + + $v = $this->$func(); + + if ($v) { + $this->args[$i] = $v; + } + + $i++; + } + } + public function send() { $transport = Transport::fromDsn('native://default');//smtp://localhost $mailer = new Mailer($transport); + $this->loadDetails(); $body = $this->getBody(); $to = self::convertVars($this->args[1]); @@ -77,7 +103,7 @@ class MailerFix extends Email { // admin_email can have a string or an array config // https://docs.silverstripe.org/en/4/developer_guides/email/#administrator-emails - $adminEmail =Email::config()->get('admin_email'); + $adminEmail = Email::config()->get('admin_email'); if (is_array($adminEmail) && count($adminEmail ?? []) > 0) { $defaultFrom = array_keys($adminEmail)[0]; } else {