No line endings when using MarkupInterface in legacy mails

Created on 9 July 2025, 6 days ago

Problem/Motivation

When building an email by adding MarkupInterface instances (most commonly, by calling t()) to the body array, this gives a different result than when using plain strings (and importantly, also a different result as with core Drupal mail or Mail System), in that the text from the body parts is stuck together, without any line ending in between.

Also note that the documentation for hook_mail states "An array of lines containing the message to be sent. Drupal will format the correct line endings for you." (emphasis mine).

Steps to reproduce

  • Build a legacy email by implementing hook_mail.
  • Build the body array by adding at least to MarkupInterface items, e.g.
    $message['body'][] = t('This is the first line.');
    $message['body'][] = t('This is the second line.');
    
  • Trigger the sending of the mail
  • Notice how the two lines are stuck together

Proposed resolution

When building the legacy mail, first render the markup items into a string, and then treat them the same way as a plain string (by putting them in a processed_text render element).

Remaining tasks

  • Create merge request
  • Review
  • Merge

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇱Netherlands eelkeblok Netherlands 🇳🇱

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

Comments & Activities

Production build 0.71.5 2024