Replace [code] and [length] tokens in email subject

Description

Currently, the [code] and [length] placeholders are only replaced in the email body when sending the OTP email. As a result, if these placeholders are used in the email subject, they remain unchanged and appear literally in the subject line.

This pull request applies the same token replacement logic to the email subject as already implemented for the email body. This ensures that [code] and [length] can be used consistently in both the subject and the body of the authentication email.

Before

[code] and [length] are replaced in the body only.

If used in the subject, the placeholders are not replaced.

After

[code] and [length] are replaced in both the subject and the body, providing consistent behavior.

Change introduced

// Replace tokens in the email subject.
$subject = str_replace($search, $replace, $this->emailSetting['subject']);

$this->message = [
  'subject' => $subject,
  'langcode' => $this->langCode,
  'body' => $body,
];

This mirrors the existing replacement logic used for the email body and allows site administrators to include the authentication code directly in the email subject if desired.

Benefits

  • Consistent token behavior between subject and body
  • More flexibility for administrators configuring authentication emails
Edited by amdcm

Merge request reports

Loading