Email message body not formatted correctly w/PHP 8

9 posts by 3 authors in: Forums > CMS Builder
Last Post: August 30, 2022   (RSS)

By Deborah - June 7, 2022

I am experiencing issues with CMSB 3.55 and 3.56 emails.

It's happening with various email templates, the Auto Backup plugin email, and the password reset email. The body of the messages contain raw HTML and the Auto Backup does not send a zip attachment of the backup. I am using PHP's built-in mail() function in the settings.

The following two examples happen with CMSB v3.55 or v3.56 with PHP 8.0.18 or 8.1.5 (same results with any combo). Setting back to PHP 7.4 works fine.

#1 - Example from /admin.php?menu=forgotPassword

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.=">
<html xmlns=3D"http://www.=">
<meta http-equiv=3D"Content-Type" content=3D=
"text/html; charset=3Dutf-8">
<title>CMS Password Reset</title>


<style type=3D"text/css">
  p { margin-bottom: 1em; }

<p>You requested a passw=
ord reset for CMS.</p>
<p>To reset your password click this link:<br /><a=
<p>This requ=
est was made from IP address: (removed)</p></body>

#2 - Partial Example from Auto Backup v1.04 Plugin:

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Automatically generated backup file.

Content-Type: application/octet-stream;
Content-Transfer-Encoding: base64
Content-Disposition: attachment;

... (removed large block)


I'm not sure what to do or check. Thanks in advance for any ideas.

~ Deborah

By daniel - June 14, 2022

Hi Deborah,

This is an odd issue, but not the first we've seen it. Could you let me know what email client you're using, and possibly try to send out to some different email addresses using different clients (e.g. gmail, outlook, etc.)? I wasn't able to find any specific discrepancies between how PHP 7.4 and 8.1 send out emails, so it may help to check for any client differences.


Technical Lead

By Deborah - June 14, 2022

Daniel, I appreciate your reply. If you can't replicate the issue, then there is hope!

I'm viewing email received in Microsoft Outlook 2016. Emails generated by CMSB installs prior to 3.55 or 3.56 (with older PHP versions) still look good.

I'll try sending to other email clients and let you know what I find.

Thanks again!
~ Deborah

By daniel - June 14, 2022

Thanks for the info Deborah! Keep me posted on what you find with other email clients.

A few other questions that might help narrow things down:

  • If possible, are you able to test using a Pre-v3.55 CMSB install running PHP 8? This is outside compatibility and will likely generate errors so I understand if you're not able to do this, but it would help to know if the combination of CMSB and PHP versions has any effect, of if it's purely an issue with PHP 8.
  • For the site(s) having the issue, on the Email Settings configuration page, is "How to send mail" set to use PHP's built-in mail() function, or is it set up to send through an SMTP server? 


Technical Lead

By Deborah - June 15, 2022

Daniel, thanks for the ideas for narrowing things down. No luck yet, but here's where I'm at:

  • I tried, but am not able to run pre-v3.55 installs when switched to PHP 8, because errors prevent the admin login screen from displaying.
    ERROR: "Too few arguments to function _errorlog_catchRuntimeErrors()...." (removed the rest of this message)
  • I am using PHP's built-in mail() function. I've not been able to get SMTP connections to connect for many versions and am not able to with 3.56 either.
  • Today I tried a fresh install of 3.56 on a different server (updated to PHP 8.0.20) and got the same email template errors, with the HTML displaying in the body of the message.
  • In addition to sending password reset emails to Microsoft Outlook on my PC, I also sent to Gmail and and see the same email issue.

I've now tested on at least 4-5 different installs over two different servers and all emails are coming through similarly.
There are equal signs "=" randomly inserted into the messages, which could be breaking the HTML

<p>You request=
ed a password reset for CMS Builder.</p>
<p>To reset your password click =
this link:

I've exhausted all of my testing ideas here. If you have other suggestions of things for me to try, I'd be happy to do so.

Thanks for your help on this!
~ Deborah

By Dave - June 16, 2022

Hi Deborah, 

We had a look into this and it appears to be a known issue with PHP 8:

They changed how the internal PHP mail() function works so that it requires a multicharacter line ending (\r\n instead of \r\n or \n).  We can try changing it, but it may cause it not to work on other servers.  The PHP docs reference that here:

Note: If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.

Sometimes what we do in these cases is add code that detects the PHP version to work around version-specific issues.  Often they revert it back a few versions later if it breaks too many servers.

We'll need to investigate further to find a universally workable solution, but try this: 

  • Open cmsb/3rdParty/SwiftMailer5/classes/Swift/Transport/SendmailTransport.php
  • Search for "\n"
  • Comment out the line in the else block
if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) {
  $buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."));
} else {
  # Comment this line # $buffer->setWriteTranslations(array("\r\n" => "\n"));

Let me know if that makes a difference.  If not could you fill out a second level support request here:

Hope that helps!

Dave Edis - Senior Developer

By Deborah - June 16, 2022


Your idea seems a good explanation for what I'm seeing with the random message line breaks.

I tried commenting out the else block, but still see the same. I'll submit a support request, as you suggested.

Thanks very much for looking at this.

~ Deborah

By daniel - August 29, 2022

Hi all,

We were finally able to resolve this issue. It can be fixed by commenting out these lines (165-168) in /cmsb/3rdParty/SwiftMailer5/classes/Swift/Transport/MailTransport.php:

$headers = str_replace("\r\n", PHP_EOL, $headers);
$subject = str_replace("\r\n", PHP_EOL, $subject);
$body = str_replace("\r\n", PHP_EOL, $body);
$to = str_replace("\r\n", PHP_EOL, $to);

Note that this is a system-specific fix, i.e. only make this fix if your site is exhibiting the issue. It can happen on some Linux servers running PHP 8+, but not all. It is not backwards-compatible with PHP 7, so it won't be added to the official CMSB release. We will instead continue looking at a long-term fix that can be backwards compatible.


Technical Lead