Skip to content

Commit

Permalink
Merge pull request #1020 from kenjis/fix-html-mail
Browse files Browse the repository at this point in the history
fix: Shield may not send correct HTML mail
  • Loading branch information
datamweb authored Feb 13, 2024
2 parents 524ceba + 18c9220 commit ce49903
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/Authentication/Actions/Email2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ public function handle(IncomingRequest $request)

// Send the user an email with the code
helper('email');
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email = emailer(['mailType' => 'html'])
->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email->setTo($user->email);
$email->setSubject(lang('Auth.email2FASubject'));
$email->setMessage($this->view(setting('Auth.views')['action_email_2fa_email'], ['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date]));
$email->setMessage($this->view(
setting('Auth.views')['action_email_2fa_email'],
['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
['debug' => false]
));

if ($email->send(false) === false) {
throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers']));
Expand Down
9 changes: 7 additions & 2 deletions src/Authentication/Actions/EmailActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ public function show(): string

// Send the email
helper('email');
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email = emailer(['mailType' => 'html'])
->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email->setTo($userEmail);
$email->setSubject(lang('Auth.emailActivateSubject'));
$email->setMessage($this->view(setting('Auth.views')['action_email_activate_email'], ['code' => $code, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date]));
$email->setMessage($this->view(
setting('Auth.views')['action_email_activate_email'],
['code' => $code, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
['debug' => false]
));

if ($email->send(false) === false) {
throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers']));
Expand Down
9 changes: 7 additions & 2 deletions src/Controllers/MagicLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ public function loginAction()

// Send the user an email with the code
helper('email');
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email = emailer(['mailType' => 'html'])
->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
$email->setTo($user->email);
$email->setSubject(lang('Auth.magicLinkSubject'));
$email->setMessage($this->view(setting('Auth.views')['magic-link-email'], ['token' => $token, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date]));
$email->setMessage($this->view(
setting('Auth.views')['magic-link-email'],
['token' => $token, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
['debug' => false]
));

if ($email->send(false) === false) {
log_message('error', $email->printDebugger(['headers']));
Expand Down
4 changes: 3 additions & 1 deletion src/Helpers/email_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* Provides convenient access to the CodeIgniter Email class.
*
* @param array<string, mixed> $overrides Email preferences to override.
*
* @internal
*/
function emailer(array $overrides = []): Email
Expand Down Expand Up @@ -46,7 +48,7 @@ function emailer(array $overrides = []): Email
];

if ($overrides !== []) {
$config = array_merge($overrides, $config);
$config = array_merge($config, $overrides);
}

/** @var Email $email */
Expand Down

0 comments on commit ce49903

Please sign in to comment.