Problem/Motivation
With the contributed module Symfony Mailer installed and configured in a Drupal 11.x site, site emails, including the password reset email, html-encode quotation marks and similar characters in the body of the message. Such emails contain tokens for example the site name. So, as an example, if a site name has apostrophes (single quotes) in it like 'L'Entreprise' then they are converted to HTML entities in the email body.
BEFORE
The text as seen in the sent email with Symfony mailer installed:
AFTER
The same email with the fix applied, with the single quotations displayed correctly:
There is a fix for this behaviour at line 785 of the user.module file:
BEFORE
$message['subject'] .= PlainTextOutput::renderFromHtml($token_service->replace($mail_config->get($key . '.subject'), $variables, $token_options));
$message['body'][] = $token_service->replace($mail_config->get($key . '.body'), $variables, $token_options);
AFTER
$message['subject'] .= PlainTextOutput::renderFromHtml($token_service->replace($mail_config->get($key . '.subject'), $variables, $token_options));
$message['body'][] = PlainTextOutput::renderFromHtml($token_service->replace($mail_config->get($key . '.body'), $variables, $token_options));
Steps to reproduce
Install Drupal 11.x using the standard profile.
Change the site name to 'L'Entreprise'.
Install the Symfony mailer module.
Set the Symfony mailer as the default mailer.
Generate an email for a new user or create a password reset email for a user and sent it.
View the email.
Proposed resolution
Apply the function PlainTextOutput::renderFromHtml
to the body of the emails then apostrophes and quotes and other special characters will be displayed as plain text.
API changes
N/A
Remaining tasks
There is an MR with a fix. There is also now a test. But the test will always pass until tested with the Symfony mailer contributed module installed and configured. It is necessary to find a way of applying a test-only test that fails.