$content_title = $translated_entity->getTitle();
          $url_alias = \Drupal::service('pathauto.alias_cleaner')
          $content_link = <<<link
    <a href='/publications/$url_alias'>$url_alias</a>
          $params['node_title'] = 'Chaire ANMT – Nouvelle Publication : ' . $entity->label() . '';
          $params['message'] = <<<msg
    Nouvelle publication : $content_title $content_link. \n
//some code
  $result = $mailManager->mail($module, $key, $subscriber, $langcode, $params, null, $send);

The email generated do not place the link next to the content title. How to fix that?

enter image description here

1 Answer 1


That is expected, when the Drupal mail back-end that comes with Drupal, implemented by the PhpMail class, is used. In fact, its format() method contains the following code.

  // Join the body array into one string.
  $message['body'] = implode("\n\n", $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']);

MailFormatHelper::htmlToText() is the method that changes the HTML markup as you see.

The only way to avoid that is to use a different mail back-end or implement one in a custom module.

  • what is the simplest alternative plugin/service that allows HTML in emails ?
    – Matoeil
    Commented May 17, 2023 at 14:37
  • 2
    For Drupal 9.4/10, I would say that is the Drupal Symfony Mailer module. I have never used it, but its documentation page says it fully supports HTML mails.
    – apaderno
    Commented May 17, 2023 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.