Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: Fehlerbehebung phpmailer.php Deprecated: preg_replace(): on line 1438

    rjung

    • Mitglied
    • Beiträge: 119
    • Geschlecht:
    Ich hoffe ich bin hier richtig .. ansonsten bitte in die richtige Kategorie verschieben.

    Da mir nun auch schon sehr oft schnell geholfen wurde möchte ich auch mal was beitragen  :-)

    Eine kleine Hilfe für alle PHP 5.5 geschädigten mit dem DHL DHL Intraship bzw. DHL Label Modul. Ich hab auch ne weile nach der Lösung gesucht. Ob sie 100 % richtig ist möchte ich nicht versprechen, aber sie funktioniert bei mir.

    Ab PHP 5.5 kommt beim Erzeugen eines DHL Labels bzw. beim Stornieren folgende Fehlermeldung:

    Code: PHP  [Auswählen]
    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in (euer serverpfad) ... /includes/classes/class.phpmailer.php on line 1438

    Daraus resultiert dann eine weitere " Cannot modify header information .... "  Fehlermeldung

    Lösungsansatz :

    in der "includes/classes/class.phpmailer.php"

    den Abschnitt :

    Code: PHP  [Auswählen]
    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 */
            $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;
      }

    ersetzen mit :

    Code: PHP  [Auswählen]
    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);
        }

    Code ist aus der  https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php

    Wie gesagt, das ganze ohne Garantie.

    Grüße
    René

    Linkback: https://www.modified-shop.org/forum/index.php?topic=33917.0

    Fakrae

    • Viel Schreiber
    • Beiträge: 997
    Wobei das streng genommen keine Fehlermeldung ist, lediglich eine Warnung. Das Programm sollte im Hintergrund normal funktionieren und gibt halt nur die Warnung aus, dass es in Zukunft wohl nicht mehr unbedingt funktionier (wenn man eine noch höhere PHP-Version benutzt)