Skip to content

Commit ce49903

Browse files
authored
Merge pull request #1020 from kenjis/fix-html-mail
fix: Shield may not send correct HTML mail
2 parents 524ceba + 18c9220 commit ce49903

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/Authentication/Actions/Email2FA.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ public function handle(IncomingRequest $request)
8888

8989
// Send the user an email with the code
9090
helper('email');
91-
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
91+
$email = emailer(['mailType' => 'html'])
92+
->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
9293
$email->setTo($user->email);
9394
$email->setSubject(lang('Auth.email2FASubject'));
94-
$email->setMessage($this->view(setting('Auth.views')['action_email_2fa_email'], ['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date]));
95+
$email->setMessage($this->view(
96+
setting('Auth.views')['action_email_2fa_email'],
97+
['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
98+
['debug' => false]
99+
));
95100

96101
if ($email->send(false) === false) {
97102
throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers']));

src/Authentication/Actions/EmailActivator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ public function show(): string
6565

6666
// Send the email
6767
helper('email');
68-
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
68+
$email = emailer(['mailType' => 'html'])
69+
->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
6970
$email->setTo($userEmail);
7071
$email->setSubject(lang('Auth.emailActivateSubject'));
71-
$email->setMessage($this->view(setting('Auth.views')['action_email_activate_email'], ['code' => $code, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date]));
72+
$email->setMessage($this->view(
73+
setting('Auth.views')['action_email_activate_email'],
74+
['code' => $code, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
75+
['debug' => false]
76+
));
7277

7378
if ($email->send(false) === false) {
7479
throw new RuntimeException('Cannot send email for user: ' . $user->email . "\n" . $email->printDebugger(['headers']));

src/Controllers/MagicLinkController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,15 @@ public function loginAction()
121121

122122
// Send the user an email with the code
123123
helper('email');
124-
$email = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
124+
$email = emailer(['mailType' => 'html'])
125+
->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '');
125126
$email->setTo($user->email);
126127
$email->setSubject(lang('Auth.magicLinkSubject'));
127-
$email->setMessage($this->view(setting('Auth.views')['magic-link-email'], ['token' => $token, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date]));
128+
$email->setMessage($this->view(
129+
setting('Auth.views')['magic-link-email'],
130+
['token' => $token, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date],
131+
['debug' => false]
132+
));
128133

129134
if ($email->send(false) === false) {
130135
log_message('error', $email->printDebugger(['headers']));

src/Helpers/email_helper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
/**
1818
* Provides convenient access to the CodeIgniter Email class.
1919
*
20+
* @param array<string, mixed> $overrides Email preferences to override.
21+
*
2022
* @internal
2123
*/
2224
function emailer(array $overrides = []): Email
@@ -46,7 +48,7 @@ function emailer(array $overrides = []): Email
4648
];
4749

4850
if ($overrides !== []) {
49-
$config = array_merge($overrides, $config);
51+
$config = array_merge($config, $overrides);
5052
}
5153

5254
/** @var Email $email */

0 commit comments

Comments
 (0)