Jump to content

Archived

This topic is now archived and is closed to further replies.

tirin

problem with preg_replace in phpmailer

Recommended Posts

Hi

 

I have a problem in class.phpmailer.php because the use of /e modifier is deprecated for function preg_replace. The error says that i need change for preg_replace_callback function, but i cant get it ok.

Now i have changed the code and delete de e modifier for dont have errors but i dont know the correct way to change the code for using the preg_replace_callback function.

 

Someone can say me how i change this code for use the preg_replace_callback function??

 

  $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);

 

if y change directly the function the page return an error in argument number 2..

 

  $encoded = preg_replace_callback("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);

 

thank you

 

Share this post


Link to post
Share on other sites

Thank you

I change my code and at the moment dont returns error when the web send emails.

 

Can you confirm that the change is correcT???

 

 

Thank you

 

Sorry for my english

 

 

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

 

 

Share this post


Link to post
Share on other sites

I suspect it's not correct, but not being all that familiar with the usage of preg_replace_callback(), I can't tell you for sure. I suggest you go back to that page and follow some of the side links for other similar questions and answers and discussion. For instance, you use $match, but where is it set? $stuff is defined outside this section, but is it used within the function?

 

You might feed your code a given input, and see if it comes up with the expected output. Or, if this code is from an older version of osC, you might grab the current (2.3.4BS) version to see what it has been updated to.

Share this post


Link to post
Share on other sites

Line 2903:

                $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);

Looks like that part of the code has ben rewriten. Current version is 5.2.16.

Share this post


Link to post
Share on other sites

×