- Issue created by @Pawelgorski87
- Status changed to Postponed: needs info
12 months ago 9:11pm 20 December 2023 - 🇦🇺Australia imclean Tasmania
Prior to 2.2.4, selecting HTML would force all emails to be HTML. For example, password reset emails generated by Drupal are plain text, but PHPMailer SMTP was forcing them to be html, which they shouldn't be.
Selecting HTML in version 2.2.4 respects the content-type header so if the content-type is text/plain then it won't convert it to HTML.
Which emails are plain text and how are they being generated? Notifications, password reset, form submissions etc.
- 🇵🇱Poland Pawelgorski87
Hello, thx for quick response, so our case, we have custom module where
we have function, which is run in quee:$params = [ 'subject' => $subject, 'body' => $mail, ]; $this->mailManager->mail('notifications', 'notification', $email, 'en', $params);
where $mail is string with html css etc from twig.
We have to setup header html manually in that case?
in 2.2.3 mail have 2 versions - plain and html, now in our case only plain text is sent.I debug today and in our case format HTML i changed to $format = 'plain_text'; in 386 line
- Issue was unassigned.
- Status changed to Needs review
12 months ago 12:33pm 21 December 2023 - Status changed to Active
12 months ago 2:08am 23 December 2023 - 🇦🇺Australia imclean Tasmania
There's no patch or MR to review here.
I'm not sure forcing HTML on plain text emails is a good idea. There isn't enough information in the body text to generate useful HTML.
If you're sending custom emails you can set the "Content-Type" header. This can be set for specific emails or all emails, which gives the greatest control to the modules ending the email rather than just the formatter and delivery agent.
See hook_mail_alter() to see how to set the headers.
- 🇦🇷Argentina OPtii
I fixed it using hook_mail_alter() and set text/html in Content-Type:
"nl2br" is also used to avoid losing the
when going from plain text to html
function my_custom_module_mail_alter(&$message) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
$message['body'][0] = nl2br($message['body'][0]);
} - 🇵🇱Poland Pawelgorski87
Hi, imclean, I know how to set a header, but earlier non coders users just download that module and just check HTML mails. After that every mails were send by html. Now they have to add some extra modules etc... . I fixed my project in hook_alter. Maybe there should be 3 option in settings? something like - send all email as html?
- 🇦🇺Australia imclean Tasmania
I'm still not clear on the benefit of this change.
Now, aso Drupal notifications that contain links are also only in plain text, previously, when HTML was checked in settings, you could click them directly from the email, because Drupal converted them to ahref tag. Now you need to alter all emails to manually add a new header.
I've just tested sending a plain text email with a URL and the URL is converted to a link by the mail client, in this case Thunderbird. I'm sure Apple Mail, GMail, Outlook and others also have this capability.
I also tried using the previous logic and requesting a password reset email with the format set to HTML. In this case, HTML is forced but the body of the text contains the URL in plain text instead of a link. There is no conversion done to the body to add links or even line breaks, as mentioned in #7.
In your case, you're sending email in a custom module so it's easy enough to set the required Content-Type header.
- 🇦🇺Australia imclean Tasmania
This adds an option "Send all email as HTML" when "HTML" format is selected. I'm not sure how it will help as it does no conversion of plain text to HTML so the plain text body will be displayed as it is supplied.
Please test to see if it does what you expect. What specific scenarios does it help with?
- Status changed to Needs review
11 months ago 2:43am 9 January 2024 - Status changed to Closed: won't fix
10 months ago 4:18am 13 February 2024 - Status changed to RTBC
10 months ago 9:19am 13 February 2024 - 🇵🇱Poland Pawelgorski87
imclean, hi sorry for late reposne, Yes, all works good with that option, I think it should go to main version ;)
- Status changed to Fixed
10 months ago 9:32pm 18 February 2024 - Status changed to Fixed
10 months ago 10:18pm 25 February 2024