Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2016-07-14 01:44:21

Samoreen
Member
From: Samoreau, France
Registered: 2015-04-22
Posts: 146
Website

Contact form not working

Hi,

I got the following error message when trying to send an email:

Something went wrong
preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in PHPMailer.php on line 1442

Did Backlight shoot itself in the foot ? :-)
Should I modify the source code myself as indicated?


Patrick

Offline

#2 2016-07-14 06:33:22

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Contact form not working

Hi Patrick, it looks like PHPMailer (third party code shipped with Backlight) is using functions that are no longer compatible with your server.  This fix unfortunately involves updating several lines of code.  If you're keen to try it let me know and I'll advise where to change the code.

For the longer term, I will need to look at updating PHPMailer in our code base.

Offline

#3 2016-07-14 06:39:33

Samoreen
Member
From: Samoreau, France
Registered: 2015-04-22
Posts: 146
Website

Re: Contact form not working

Ben,

For the moment, my server is a Synology NAS running Apache HTTP Server 2.2 and PHP 5.6. I have no problem updating the code. Just tell me what to change.

Thanks.


Patrick

Offline

#4 2016-07-14 06:49:34

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Contact form not working

Hi Patrick, great.  Can you try swapping out the method "function encodeQ" in backlight/lib/framework/PHPMailer.php with that from the latest version at https://github.com/PHPMailer/PHPMailer/ … mailer.php

I suggest renaming the old method to something like function encodeQ_old and adding the new version after it so that the change can be easily reversed if needed.  The full function is pasted here:

public function encodeQ($str, $position = 'text')
    {
        // There should not be any EOL in the string
        $pattern = '';
        $encoded = str_replace(array("\r", "\n"), '', $str);
        switch (strtolower($position)) {
            case 'phrase':
                // RFC 2047 section 5.3
                $pattern = '^A-Za-z0-9!*+\/ -';
                break;
            /** @noinspection PhpMissingBreakStatementInspection */
            case 'comment':
                // RFC 2047 section 5.2
                $pattern = '\(\)"';
                // intentional fall-through
                // for this reason we build the $pattern without including delimiters and []
            case 'text':
            default:
                // RFC 2047 section 5.1
                // Replace every high ascii, control, =, ? and _ characters
                $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
                break;
        }
        $matches = array();
        if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
            // If the string contains an '=', make sure it's the first thing we replace
            // so as to avoid double-encoding
            $eqkey = array_search('=', $matches[0]);
            if (false !== $eqkey) {
                unset($matches[0][$eqkey]);
                array_unshift($matches[0], '=');
            }
            foreach (array_unique($matches[0]) as $char) {
                $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
            }
        }
        // Replace every spaces to _ (more readable than =20)
        return str_replace(' ', '_', $encoded);
    }

Offline

#5 2016-07-14 17:02:10

Samoreen
Member
From: Samoreau, France
Registered: 2015-04-22
Posts: 146
Website

Re: Contact form not working

Thanks Ben, that worked flawlessly.


Patrick

Offline

#6 2016-07-14 21:32:48

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Contact form not working

Thanks for confirming Patrick.  I have made the same change in our codebase, to be part of the next maintenance update.

Offline

Board footer

Powered by FluxBB