FIX: outdated swift mailer breaking mails formating

This commit is contained in:
Tony Air 2024-03-29 18:39:06 +02:00
parent cfdd069de5
commit 914ad595f0

View File

@ -26,17 +26,43 @@ class MailerFix extends Email
parent::__construct($from, $to, $subject, $body, $cc, $bcc, $returnPath); parent::__construct($from, $to, $subject, $body, $cc, $bcc, $returnPath);
} }
private static function convertVars($mails) private static function convertVars($mails)
{ {
return is_array($mails) ? implode(' ', $mails) : $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() public function send()
{ {
$transport = Transport::fromDsn('native://default');//smtp://localhost $transport = Transport::fromDsn('native://default');//smtp://localhost
$mailer = new Mailer($transport); $mailer = new Mailer($transport);
$this->loadDetails();
$body = $this->getBody(); $body = $this->getBody();
$to = self::convertVars($this->args[1]); $to = self::convertVars($this->args[1]);
@ -77,7 +103,7 @@ class MailerFix extends Email
{ {
// admin_email can have a string or an array config // admin_email can have a string or an array config
// https://docs.silverstripe.org/en/4/developer_guides/email/#administrator-emails // 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) { if (is_array($adminEmail) && count($adminEmail ?? []) > 0) {
$defaultFrom = array_keys($adminEmail)[0]; $defaultFrom = array_keys($adminEmail)[0];
} else { } else {