System throw a warning sending mails:

Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in Drupal\smtp\PHPMailer\PHPMailer->EncodeQ() (line 1762 of modules/contrib/smtp/src/PHPMailer/PHPMailer.php).

  public function EncodeQ($str, $position = 'text') {
    // There should not be any EOL in the string
    $encoded = preg_replace('/[\r\n]*/', '', $str);

    switch (strtolower($position)) {
      case 'phrase':
        $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
        break;
      case 'comment':
        $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
      case 'text':
      default:
        // Replace every high ascii, control =, ? and _ characters
        //TODO using /e (equivalent to eval()) is probably not a good idea
        $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
              "'='.sprintf('%02X', ord('\\1'))", $encoded);
        break;
    }

    // Replace every spaces to _ (more readable than =20)
    $encoded = str_replace(' ', '_', $encoded);

    return $encoded;
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

estoyausente created an issue. See original summary.

estoyausente’s picture

Status: Active » Needs review
FileSize
1.57 KB

Changing it to preg_replace_callback (more info: http://php.net/manual/es/function.preg-replace-callback.php)

ptmkenny’s picture

Status: Needs review » Needs work

Confirmed the error exists as described in the original issue.
Applied the patch on Drupal 8.0.2 on Pantheon.
The deprecated error is fixed, but now I get a new error:

Warning: preg_replace_callback(): Requires argument 2, '5C', to be a valid callback in Drupal\smtp\PHPMailer\PHPMailer->EncodeQ() (line 1761 of modules/smtp/src/PHPMailer/PHPMailer.php).

estoyausente’s picture

Status: Needs work » Closed (won't fix)

Sorry, it was my fail.

This is a PHPMailer task and it should to be resolved in their github.
https://github.com/PHPMailer/PHPMailer/issues/187

And really, it's done but we are using a old phpMailer version (5.1).

olilo’s picture

Hello

Is it a new patch planed to fix the new warning message after applying this patch:

Warning: preg_replace_callback(): Requires argument 2, '5C', to be a valid callback in Drupal\smtp\PHPMailer\PHPMailer->EncodeQ() (line 1761 of modules/smtp/src/PHPMailer/PHPMailer.php)

I don't see this issue on the github of PHPmailer

It is good to have a patch to fix a warning error message but if you receive another one in place...

estoyausente’s picture

It is patched several years ago. We are using a very old library version. I'm trying to port it using a new version and Composer for controlling the dependency:
https://www.drupal.org/node/2711559

But... need more hands or more time :)