Encode a line break in an HTML email sent by Rules?

by Sam   Last Updated August 21, 2018 16:07 PM

I have a rule that sends out an email when a node gets edited in a certain way. The rule fills the body of the email with the value of a <textarea> field from the node that was updated.

The email is being sent out in HTML format (not plain text) and the <textarea> is set to plain text (not Filtered Text).

When the email gets delivered, the HTML line breaks (<br />) that I've entered into the <textarea> field are not respected (they get encoded); it just one big mass of text with no line breaks.

What do I have to put in the <textarea> field for line breaks to come out in the HTML email?

I've tried:

  • <br>
  • <br />
  • \n
  • \r
  • \r\n
  • %0D%0A
  • &#x3C;br /&#x3E;
  • %3Cbr+%2F%3E

Any HTML I put in the field gets encoded and not processed as HTML. How do I put in <br /> and have it stay as HTML?

Tags : rules emails


Answers 1


You can try the code

/**
 * Implements hook_mail().
 */
function mymodule_mail($key, &$message, $params) {
  $headers = array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal'
  );
  foreach ($headers as $key => $value) {
    $message['headers'][$key] = $value;
  }
  $message['subject'] = $params['subject'];
  $message['body'] = $params['body'];
}
vinhdv
vinhdv
August 21, 2018 15:33 PM

Related Questions




Rules Failing to Send Account Emails

Updated February 13, 2018 20:07 PM