Unable to use HTML Markup in Body field, without Mail MIME installed.

Created on 8 October 2018, about 6 years ago
Updated 10 May 2023, over 1 year ago

It looks like it is currently not possible to use HTML markup within the body field of an email, unless you are using the Mime Mail module.
This issue is introduced in the format() function of the HTMLMailSystem Plugin. (src/Plugin/Mail/HTMLMailSystem.php)

You can see in the below snippet that the message body is getting converted to Plain text, and all HTML tags are stripped.

    // Collapse the message body array.
    if ($this->configVariables->get('htmlmail_use_mime_mail')) {
      $body = $this->formatMailMime($message);
      $plain = $message['MailMIME']->getTXTBody();
    }
    else {
      // Collapse the message body array.
      if (is_array($message['body'])) {
        // Join the body array into one string.
        $message['body'] = implode("$eol$eol", $message['body']);
        // Convert any HTML to plain-text.
        $message['body'] = MailFormatHelper::htmlToText($message['body']);
        // Wrap the mail body for sending.
        $message['body'] = MailFormatHelper::wrapMail($message['body']);
      }

This may have been added intentionally as a security best practice, but in the Drupal 7 module, this behavior was not present and you could add HTML directly to your message body.

I'm attaching a patch which removes this behavior, in case anyone else is encountering problems with it.
But there might be a more appropriate way to allow for this functionality and still have some level of sanitization for security purposes.

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States nplowman

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024