【问题标题】:=?utf-8 in mail subject phpmailer=?utf-8 在邮件主题 phpmailer
【发布时间】:2012-12-25 00:35:32
【问题描述】:

如何编辑我的函数以摆脱

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

在邮件主题中?

此函数(EncodeHeader)是邮件消息的编码标头,需要以某种方式更正。代码如下:

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;
}

我听说必须编码的字符不能放在引号中。

这件事在“这是新的工作主题”这样的消息上效果很好,但在这不是“рабочий инструмент”上崩溃了。

【问题讨论】:

  • 不要建立自己的 mime 电子邮件。只需使用 PHPMailer 或 Swiftmailer,让他们自己处理。您会发现您的电子邮件已减少到 4 或 5 行代码(对于基本的),v.s.数以百万计的人试图自己做所有事情。
  • 这已经是PHPMailer了。

标签: php email phpmailer


【解决方案1】:

http://swiftmailer.org/ 试试这个会对你有所帮助。它处理所有的编码。

【讨论】:

  • 它已经带有用于 wordpress 的 cform 插件。这不是一个选择
猜你喜欢
  • 2011-11-26
  • 1970-01-01
  • 2015-12-06
  • 1970-01-01
  • 2012-03-10
  • 2017-07-15
  • 1970-01-01
  • 2013-06-08
  • 2015-10-01
相关资源
最近更新 更多