koe
koe

Reputation: 746

Deprecated: preg_replace(): The /e modifier is deprecated in phpmailer

I am using class.phpmailer.php to send email from my local server, it's processing well in my local server with PHP version php5.3.4 but after I update PHP version to 5.5.4 it's showing the following message:

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in class.phpmailer.php`

This is the line causing the error:

$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);

Upvotes: 8

Views: 15105

Answers (2)

switch (strtolower($position)) {
  case 'phrase':
    //$encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
    $encoded = preg_replace_callback("/([^A-Za-z0-9!*+\/ -])/e",function($m) { return '='.sprintf('%02X', ord(stripslashes($m[1]))); }, $encoded);
    break;
  case 'comment':
    //$encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
    $encoded = preg_replace_callback("/([\(\)\"])/e",function($m) { return '='.sprintf('%02X', ord(stripslashes($m[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);
    $encoded = preg_replace_callback('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',function($m) { return '='.sprintf('%02X', ord(stripslashes($m[1]))); }, $encoded);
    break;
}

yes. it's work on php 7.2.

Upvotes: 2

Samosa
Samosa

Reputation: 845

Try and Replace:

This

$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',"'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);

With

$encoded = preg_replace_callback('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',function($m) { return '='.sprintf('%02X', ord(stripslashes($m[1]))); }, $encoded);

Upvotes: 14

Related Questions