timofeiMih
timofeiMih

Reputation: 109

=?utf-8 in mail subject phpmailer

How can I edit my function to get rid of

"=?utf-8?B?0JfQsNC60LDQtyDQstGL0L/QuNGB0LrQuCBkb2xzbm93ICIgM9C00LDQtNCw ?= "."

in mail subject?

This function(EncodeHeader) is encoding header of the mail message and needs to be corrected somehow. The code is listed below:

public function EncodeHeader($str, $position = 'text') {
$x = 0;

switch (strtolower($position)) {
  case 'phrase':
    if (!preg_match('/[\200-\377]/', $str)) {
      // Can't use addslashes as we don't know what value has magic_quotes_sybase
      $encoded = addcslashes($str, "\0..\37\177\\\"");
      if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
        return ($encoded);
      } else {
        return ("\"$encoded\"");
      }
    }
    $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
    break;
  case 'comment':
    $x = preg_match_all('/[()"]/', $str, $matches);
    // Fall-through
  case 'text':
  default:
    $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
    break;
}

if ($x == 0) {
  return ($str);
}

$maxlen = 75 - 7 - strlen($this->CharSet);
// Try to select the encoding which should produce the shortest output
if (strlen($str)/3 < $x) {
  $encoding = 'B';
  if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
    // Use a custom function which correctly encodes and wraps long
    // multibyte strings without breaking lines within a character
    $encoded = $this->Base64EncodeWrapMB($str);
  } else {
    $encoded = base64_encode($str);
    $maxlen -= $maxlen % 4;
    $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  }
} else {
  $encoding = 'Q';
  $encoded = $this->EncodeQ($str, $position);
  $encoded = $this->WrapText($encoded, $maxlen, true);
  $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
}

$encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
$encoded = trim(str_replace("\n", $this->LE, $encoded));

return $encoded;
}

I heard about that characters that must be encoded can`t be in quotes.

This thing works well on message like this "This is new working subject", but gets crashed on This is not "рабочий инструмент".

Upvotes: 1

Views: 848

Answers (1)

Ravi Sharma
Ravi Sharma

Reputation: 1182

http://swiftmailer.org/ try this will help you. it handle all the encodings.

Upvotes: 1

Related Questions