Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Send email as HTML is not working for PHP 8 but it works well with PHP 7.4. On PHP 8 the html markup is sent inside the email which creates a lot of confusion for editors.
https://www.php.net/releases/8.0/en.php#saner-string-to-number-comparisons
Maybe an operator is not catching and rendering the content.
Comment | File | Size | Author |
---|---|---|---|
#4 | Screen Shot 2021-09-29 at 10.01.48 AM.png | 13.74 KB | bernardm28 |
#3 | PHP8.png | 47.85 KB | paulocs |
#3 | PHP7.4.png | 48.34 KB | paulocs |
Comments
Comment #2
bernardm28 CreditAttribution: bernardm28 at The University of Tennessee at Chattanooga commentedComment #3
paulocsHello @bernardm28,
is it possible to see this error enabling email debugging?
If yes, can you attach a webform example or add the steps to repoduce?
Btw are you testing it with the last webform dev version?
I don't see any difference in a small test that did.
Comment #4
bernardm28 CreditAttribution: bernardm28 at The University of Tennessee at Chattanooga commentedHi, which module/technique are you using for debugging email?
https://www.drupal.org/docs/develop/local-server-setup/managing-mail-han...
I should probably test it the same way.
I'm not sure the test used on those pictures allows us to see the difference. I thought the checkbox that said Send email as HTML might have something to do with it.
Instead of Text field it should be just text field with a rendered outcome.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #6
bernardm28 CreditAttribution: bernardm28 at The University of Tennessee at Chattanooga commentedI tried replicating this issue with mail-hog and I had no luck so far. I will close so it, for now. if I see it again I will add more details.
Comment #7
bernardm28 CreditAttribution: bernardm28 at The University of Tennessee at Chattanooga commentedComment #8
alberto56 CreditAttribution: alberto56 at Dcycle commentedConfirming this does not happen on Mailhog; however on Acquia this happens. I needed to revert back to PHP 7 and it works now. I will report my findings here.
I will set this back to maintainer needs more info (even though I'm not the maintainer!).
@bernardm28 what was the environment you had issues with?
Comment #9
alberto56 CreditAttribution: alberto56 at Dcycle commentedHere is the message I got from my Acquia support ticket:
So if anyone uses Webform on Acquia and is considering moving to PHP8, make sure you test the forms on the staging environment before moving your production site to PHP8.
I will document herein any more information I get from Acquia.
Comment #10
alberto56 CreditAttribution: alberto56 at Dcycle commentedThis is not really a Webform bug at this point. Setting to "support request" instead.
Comment #11
bernardm28 CreditAttribution: bernardm28 at The University of Tennessee at Chattanooga commentedWe are on Acquia as an enterprise client. So it must be spread throughout their infrastructure.
That said we started exploring https://docs.acquia.com/cloud-platform/manage/platform-email/
their platform email as an alternative. Maybe that will work around this issue.
Comment #12
alberto56 CreditAttribution: alberto56 at Dcycle commentedThanks @bernardm28
If "platform-email" works, please document it here.
Comment #13
alberto56 CreditAttribution: alberto56 at Dcycle commentedSpecifying that this is a potential Acquia issue with Webform in the issue title.
Comment #14
alberto56 CreditAttribution: alberto56 at Dcycle commentedI am including some more info here, although I'll leave it at "postponed", as I am unable to reproduce this in isolation. According to Acquia:
In PHP 8.0 there was a change to only explode email headers only on CRLF where previously it was exploded on LF and CRLF: https://github.com/php/php-src/commit/6983ae751cd301886c966b84367fc7aaa1...
The email headers aren’t exploded correctly in Drupal core and since the headers with 8.0 don't separate, Content-Type won't get parsed and so the email will present itself as raw text.
Here is the code in Drupal core:
core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php#92:
This looks like a Drupal Core issue that is affected by the linked PHP8 change, and is probably dependent on the receiving MTA too (That's why it might be working with mail-hog, but not in the production environment).
Comment #15
ytsurkFor me this happens only (on PHP 8) with twig template emails, not with default ones.
I use swiftmailer for formatting, when also using swiftmailer as sender/transport, the emails using twig templates are no longer plain text.
BTW symfony_mailer will be the successor for swiftmailer, which is no longer maintained ... not yet tested though.
Comment #16
utcwebdev CreditAttribution: utcwebdev as a volunteer commented@alberto56, you can close this issue for the Acquia email issues. We (BernardM28 and I) have implemented Acquia Platform Email and tested/verified with PHP 8 in our dev, stage and prod environments. Acquia has deprecated their legacy mail services and require all clients to migrate to Acquia Platform Email.
Note: for Acquia Platform Email, the From: address of any email message must be associated with a verified email hostname with Acquia's required DNS SPF, CNAME and DKIM records. e.g. for our application, no-reply@cloudmail.domain.tld. We have changed all of our webform email handlers to use that From: address, and added appropriate Reply-to: addresses to the handlers.
Comment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #18
cilefen CreditAttribution: cilefen commentedComment #19
cilefen CreditAttribution: cilefen commentedComment #20
slangston CreditAttribution: slangston as a volunteer commentedWas able to get it to work just by adding a space to a core file.
D 9.4.5
PHP 8.1.8
WebForm 6.1.3
Was getting the same issue. PHP 7.4 worked fine sending an HTML email from WebForm. Switched to PHP 8.1 and the HTML was no longer formatting correctly in the received email. Checked the headers for the issue that people say prevented it (a space being added to the beginning of content-type, etc.), and sure enough, those spaces were there. They can be removed in the core file:
/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php
Line 104, add a space AFTER the \r\n and it works!
Before:
$mail_headers = str_replace("\r\n", "\n", $headers->toString());
After:
$mail_headers = str_replace("\r\n ", "\n", $headers->toString());
Comment #21
mvpfi CreditAttribution: mvpfi as a volunteer commented#20 sorts this issue out for me.
Comment #22
slangston CreditAttribution: slangston as a volunteer commentedStill not fixed as of Drupal 9.4.6
Comment #23
Vlooi Vlerke CreditAttribution: Vlooi Vlerke commentedD 9.4.8
PHP 8.1.8
WebForm 6.1.3
Was getting the same issue.
PHP 7.4 worked fine sending an HTML email from WebForm
The related issue looks like a better place to resolve this
#3270647: PhpMail : broken mail headers in PHP 8.0+ because of LF characters
Comment #24
cilefen CreditAttribution: cilefen commentedComment #25
droces CreditAttribution: droces as a volunteer commented#20 works for me.
Comment #26
kusiwa CreditAttribution: kusiwa commented#20 works very well
Comment #27
ytsurkGot hit with this again.
This time on an installation using Drupal's PhpMailer. I can confirm patch #20 works.
But - I would recommend to follow #3270647: PhpMail : broken mail headers in PHP 8.0+ because of LF characters in core for a future-proof solution.
Currently, I'm using https://www.drupal.org/files/issues/2022-10-31/3270647-32.patch