Email from contact form showing html tags

I’m experiencing the same issue as brought up in this post:

This is the text I’m getting in a test message:

<p><strong>Name:</strong> rod</p><p><strong>Email:</strong> rod_barbee@msn.com</p><p><strong>Message:</strong> This is a test email to see html tags in the sent message. Not sure why.</p><p><strong>I accept the collection of my data for the purposes outlined above:</strong> yes</p><p style="color: gray; padding-top: 1em; font-size: 90%;">Message received from contact form at <a href="https://rodbarbee.com/contact/">https://rodbarbee.com/contact/</a>
I use Outlook for my mail but this text is also appearing in the mail viewer in Bluehost.

I’m also seeing this at the top of the email. The MIME-Version part is all new.

Anybody else experiencing this with their Backlight contact forms?

Hi @rod_barbee, I can’t replicate this on my own server. There haven’t been any changes to the way emails have sent. I wonder if this is a change in how your email client handles the emails.

Can you try temporarily changing the email address on your site to my own and send a test contact email? Can you also message me the email address you use so that I can send you a test from my server?

Just sent a test email using your address

I think this is happening before the emails get to me. I use Outlook as my email client but I also checked my email online using the email reader my host (Bluehost) provides and problem was there as well.

If anyone is following, I reverted to php 7.4 from php 8 (8.0.16) and that eliminated the email formatting problem.

1 Like

Hi @rod_barbee, that’s a good discovery. I’ll try to replicate it by playing with different versions locally.

1 Like

Thanks for your help, @rod_barbee. I have found the issue and put in a silent fix, available by reinstalling the main Backlight modules in the “Backlight Modules” page.

The issue was that PHP 8.0 is fussy with the newline characters in email headers, making the mail function unable to tell that the emails should be treated as HTML. Our code included only newlines rather than both carriage returns and newlines.

3 Likes

Hi, I just see I have the same issue (Backlight 3,2,1 to Backlight 3,2,2) but the problem stay.

Update album files, update Backlight index files, clear template cache and Clear browser cache, but still the same issue

Thanks
Nico

Since this was a Backlight 4 fix, I doubt a fix was put in for the older versions.
You could try reverting to an earlier version of php, if your host allows that.

the best solution is to upgrade to Backlight 5, that way your site can remain compatible with changes in php.

Matt has made it easier to upgrade. See this:
https://blog.theturninggate.net/2023/11/18/cheaper-easier-upgrades-to-backlight-5/

1 Like

Thanks Rod,
the problem seems to come from the EmailHelper.php file who is in Backlight/Module/Module-Framework/helpers on these two lines (line 145 and 146):

$headers .= “MIME-Version: 1.0” . PHP_EOL;
$headers .= “Content-type: text/html; charset=utf-8” . PHP_EOL;

When I replace with:

$headers = “MIME-Version: 1.0\r\n”;
$headers .= “Content-type: text/html; charset=utf-8\r\n”;

Then the HTML formatting becomes good again, only the sending email becomes that of my hosting domain:

YYYYxxxx@cow.o2switch.net

That’s above my knowledge level. @Ben will need to advise.

I have replace line 137 to 172 by the following code and it work like a charm !

protected function sendEmailViaMail()
{
    if ($this->from['name']) {
        $headers = 'From: "'.$this->from['name']. '" <'.$this->from['email'].'>' . "\r\n";
    } else {
        $headers = 'From: '.$this->from['email']. "\r\n";
    }

    $headers .= "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=utf-8" . "\r\n";

    if ($this->replyTo) {
        $headers .= 'Reply-To: '. $this->replyTo['email'] . "\r\n";
    } else {
        $headers .= 'Reply-To: '. $this->from['email'] . "\r\n";
    }

    foreach ($this->cc as $cc) {
        $headers .= 'Cc: ' . $cc['email'] . "\r\n";
    }

    foreach ($this->bcc as $bcc) {
        $headers .= 'Bcc: ' . $bcc['email'] . "\r\n";
    }

    foreach ($this->to as $to) {
        if ($this->debug) {
            echo 'to: '.$to['email'].'<br/>';
            echo 'subject: '.$this->subject.'<br/>';
            echo 'message: <pre>'.$this->htmlMessage.'</pre><br/>';
            echo 'headers: <pre>'.htmlspecialchars(print_r($headers, true)).'</pre>';
        }

        return mail($to['email'], $this->subject, $this->htmlMessage, $headers);
    }
}

And YEAH ! it work for cart order confirmation e-mail too !

It is not recommended to ever update Backlight files. Your changes will get clobbered by future update, and as we’ve found before can cause unforeseen issues. We can only provide advice for code that we have provided. Consider upgrading to continue formal support.

1 Like

I know, but there are currently no plans to update. next year for sure. anyway, I think that backlight 3 will no longer be updated, right?

especially since I had just spent a good part of the day correcting the missing icons to replace them all with Fontawesome 5 Free locally, and it was afterwards that I realized that the format of the emails is corrupt… I don’t like wasting time for nothing

Likewise. Backlight has been updated. See version 5.

I know well but it’s not in the budgets currently

We did make it a little easier on the budget in our most recent update. In case you missed it, you can now upgrade from Backlight 3 with a $15 discount. Not huge, I know, but still a nice discount.

I hadn’t actually seen it. the discount isn’t huge, maybe, but the backlight isn’t expensive. the possibilities and support are top notch. It’s just that I hadn’t planned to ever put backlight this year, and solving problems on backlight is also a bit of a personal challenge. anyway, I customized my Backlight installation so much with hundreds of lines of php code that I hope everything will be kept for version 5! this is in fact one of the main reasons which slowed me down from going through version 5 until now