After update to 2.2.4, mails were sending only in plain even if HTML format was checked in settings.

Created on 20 December 2023, 12 months ago
Updated 25 February 2024, 10 months ago

Problem/Motivation

After update to 2.2.4, mails were sending only in plain even if HTML format was checked in settings.

Steps to reproduce

We used mailsystem Version: 8.x-4.4, phpmailer_smtp Version: 2.2.3, queue_mail Version: 8.x-1.6.

After update to 2.2.4 and phpmailer/phpmailer to ^6.9.
and aftre send mail in html, all mails have only plain format.

after revert to old version all works good.

Feature request
Status

Fixed

Version

2.2

Component

Code

Created by

🇵🇱Poland Pawelgorski87

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

Comments & Activities

  • Issue created by @Pawelgorski87
  • Status changed to Postponed: needs info 12 months ago
  • 🇦🇺Australia imclean Tasmania

    Prior to 2.2.4, selecting HTML would force all emails to be HTML. For example, password reset emails generated by Drupal are plain text, but PHPMailer SMTP was forcing them to be html, which they shouldn't be.

    Selecting HTML in version 2.2.4 respects the content-type header so if the content-type is text/plain then it won't convert it to HTML.

    Which emails are plain text and how are they being generated? Notifications, password reset, form submissions etc.

  • 🇵🇱Poland Pawelgorski87

    Hello, thx for quick response, so our case, we have custom module where
    we have function, which is run in quee:

          $params = [
            'subject' => $subject,
            'body' => $mail,
          ];
          $this->mailManager->mail('notifications', 'notification', $email, 'en', $params);
    

    where $mail is string with html css etc from twig.

    We have to setup header html manually in that case?
    in 2.2.3 mail have 2 versions - plain and html, now in our case only plain text is sent.

    I debug today and in our case format HTML i changed to $format = 'plain_text'; in 386 line

  • Issue was unassigned.
  • Status changed to Needs review 12 months ago
  • Status changed to Active 12 months ago
  • 🇦🇺Australia imclean Tasmania

    There's no patch or MR to review here.

    I'm not sure forcing HTML on plain text emails is a good idea. There isn't enough information in the body text to generate useful HTML.

    If you're sending custom emails you can set the "Content-Type" header. This can be set for specific emails or all emails, which gives the greatest control to the modules ending the email rather than just the formatter and delivery agent.

    See hook_mail_alter() to see how to set the headers.

  • 🇦🇷Argentina OPtii

    I fixed it using hook_mail_alter() and set text/html in Content-Type:
    "nl2br" is also used to avoid losing the
    when going from plain text to html
    function my_custom_module_mail_alter(&$message) {
    $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
    $message['body'][0] = nl2br($message['body'][0]);
    }

  • 🇵🇱Poland Pawelgorski87

    Hi, imclean, I know how to set a header, but earlier non coders users just download that module and just check HTML mails. After that every mails were send by html. Now they have to add some extra modules etc... . I fixed my project in hook_alter. Maybe there should be 3 option in settings? something like - send all email as html?

  • 🇦🇺Australia imclean Tasmania

    I'm still not clear on the benefit of this change.

    Now, aso Drupal notifications that contain links are also only in plain text, previously, when HTML was checked in settings, you could click them directly from the email, because Drupal converted them to ahref tag. Now you need to alter all emails to manually add a new header.

    I've just tested sending a plain text email with a URL and the URL is converted to a link by the mail client, in this case Thunderbird. I'm sure Apple Mail, GMail, Outlook and others also have this capability.

    I also tried using the previous logic and requesting a password reset email with the format set to HTML. In this case, HTML is forced but the body of the text contains the URL in plain text instead of a link. There is no conversion done to the body to add links or even line breaks, as mentioned in #7.

    In your case, you're sending email in a custom module so it's easy enough to set the required Content-Type header.

  • 🇦🇺Australia imclean Tasmania

    This adds an option "Send all email as HTML" when "HTML" format is selected. I'm not sure how it will help as it does no conversion of plain text to HTML so the plain text body will be displayed as it is supplied.

    Please test to see if it does what you expect. What specific scenarios does it help with?

  • Status changed to Needs review 11 months ago
  • 🇦🇺Australia imclean Tasmania
  • Status changed to Closed: won't fix 10 months ago
  • 🇦🇺Australia imclean Tasmania

    No feedback or response to the question in #10.

  • Status changed to RTBC 10 months ago
  • 🇵🇱Poland Pawelgorski87

    imclean, hi sorry for late reposne, Yes, all works good with that option, I think it should go to main version ;)

    • imclean committed 603bef85 on 2.2.x
      Issue #3409967 by imclean, Pawelgorski87: After update to 2.2.4, mails...
  • Status changed to Fixed 10 months ago
  • 🇦🇺Australia imclean Tasmania
  • Status changed to Fixed 10 months ago
  • 🇦🇺Australia imclean Tasmania
Production build 0.71.5 2024