HTML welcome email breaks if source code contains the text 'body'

Created on 29 March 2021, over 3 years ago
Updated 21 January 2023, almost 2 years ago

Problem/Motivation

When using HTML email as the welcome message, if the email code contains the text 'body' this is replaced with an entire copy of the email body.

Steps to reproduce

  1. Import a CSV file
  2. Select send email from option
  3. In email section select "HTML email" as format and paste in email source code containing <tbody> tags
  4. Import the user
  5. Resulting email will have the email body repeated wherever a tbody tag occured in the source

Proposed resolution

The issue is caused by line #866 of user_import.module:
$body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $params);

The $params array contains a parameter called 'body' that the strtr() function replaces in the body html. Every occurance of the text 'body' in the source then gets swapped with the original html source code.

I propose building another parameter array that only contains the replaceable parameters that all begin with "!". Patch file attached.

Proposed code inserted at line #865 as follows:

$replaceableParams = array();
foreach ($params as $key => $value) {
      if (!is_null($value) && $value != "" && substr($key,0,1) == "!") {
            $replaceableParams[$key] = $value;
      }
}

Line #866 change from:

$body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $params);

to:

$body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $replaceableParams);

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

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.

No activities found.

Production build 0.71.5 2024