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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bernardm28 created an issue. See original summary.

bernardm28’s picture

Issue summary: View changes
paulocs’s picture

Version: 6.0.0 » 6.x-dev
FileSize
48.34 KB
47.85 KB

Hello @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.

bernardm28’s picture

Hi, 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.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)
bernardm28’s picture

I 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.

bernardm28’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
alberto56’s picture

Status: Closed (cannot reproduce) » Postponed (maintainer needs more info)

Confirming 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?

alberto56’s picture

Here is the message I got from my Acquia support ticket:

I've submitted a report of this to my team so we can begin triaging this issue, as it is likely a fault at the platform-level; I don't think that there are any workarounds for this and PHP 8 at this time.

Unfortunately I don't have a way to provide an ETA for a fix on this, but you should be able to get around this by swapping PHP versions, if that is possible for you.

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.

alberto56’s picture

Category: Bug report » Support request

This is not really a Webform bug at this point. Setting to "support request" instead.

bernardm28’s picture

We 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.

alberto56’s picture

Thanks @bernardm28

If "platform-email" works, please document it here.

alberto56’s picture

Title: PHP8 issue - Send email as HTML - EmailWebformHandler.php » Emails get sent out as raw HTML on PHP 8 on Acquia - Send email as HTML - EmailWebformHandler.php

Specifying that this is a potential Acquia issue with Webform in the issue title.

alberto56’s picture

I 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:

    // For headers, PHP's API suggests that we use CRLF normally,
    // but some MTAs incorrectly replace LF with CRLF. See #234403.
    $mail_headers = implode("\n", $mimeheaders);

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).

ytsurk’s picture

For 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.

utcwebdev’s picture

@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.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)
cilefen’s picture

cilefen’s picture

slangston’s picture

Was 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());

mvpfi’s picture

#20 sorts this issue out for me.

slangston’s picture

Still not fixed as of Drupal 9.4.6

Vlooi Vlerke’s picture

Version: 6.x-dev » 8.x-5.x-dev
Category: Support request » Bug report
Status: Closed (outdated) » Active

D 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

cilefen’s picture

Version: 8.x-5.x-dev » 6.0.x-dev
Category: Bug report » Support request
Status: Active » Closed (duplicate)
droces’s picture

#20 works for me.

kusiwa’s picture

#20 works very well

ytsurk’s picture

Got 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