Problem/Motivation
MailHandler::sendMail() always sets a Content-Type: text/html; charset=UTF-8 header. However, when the site uses core's default mail backend (PhpMail), or any backend that inherits PhpMail::format(), the body is converted to plain text via MailFormatHelper::htmlToText() before being sent.
The result is a message whose body is plain text but whose header claims it's HTML. Mail clients then render the plain text as HTML: line breaks are lost, and since the plain-text conversion decodes HTML entities, any text that was escaped in the rendered template (order data, customer input, etc.) is interpreted as markup by the recipient's client.
The Content-Type header should match the actual body format.
Proposed resolution
Only send the HTML Content-Type header when the mail backend actually produces an HTML body. If the backend's format() method is the one declared by PhpMail, drop our override and let core's text/plain header apply.
Sites wanting HTML emails keep using an HTML-capable backend (Symfony Mailer, Mail System + Swiftmailer, etc.), which is unaffected.
Remaining tasks
- Review the MR.
User interface changes
None.
API changes
None. Sites on the default PhpMail backend will now receive Commerce emails as text/plain, matching their actual content.
Issue fork commerce-3641202
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #6
jsacksick commented