浏览代码

Now setting charset also in headers when sending mail.

gustavf 25 年之前
父节点
当前提交
18c6e4c25e
共有 2 个文件被更改,包括 28 次插入0 次删除
  1. 24 0
      functions/mime.php
  2. 4 0
      functions/smtp.php

+ 24 - 0
functions/mime.php

@@ -238,4 +238,28 @@
          return ($string);
    }
 
+   // Encode a string according to RFC 1522 for use in headers if it
+   // contains 8-bit characters
+   function encodeHeader ($string) {
+      global $default_charset;
+
+      // Encode only if the string contains 8-bit characters
+      if (ereg("[\200-\377]", $string)) {
+         $newstring = "=?$default_charset?Q?";
+         $newstring .= str_replace(" ", "_", $string);
+         
+         while (ereg("([\200-\377])", $newstring, $regs)) {
+            $replace = $regs[1];
+            $insert = "=" . bin2hex($replace);
+            $newstring = str_replace($replace, $insert, $newstring);
+         }
+
+         $newstring .= "?=";
+
+         return $newstring;
+      }
+
+      return $string;
+   }
+
 ?>

+ 4 - 0
functions/smtp.php

@@ -134,6 +134,10 @@
             $from = "<$from_addr>";
          else
             $from = $from . " <$from_addr>";
+
+         /* Encoding 8-bit characters */
+         $subject = encodeHeader($subject);
+         $from = encodeHeader($from);
          
          /* This creates an RFC 822 date */
          $date = date("D, j M Y H:i:s ", mktime()) . timezone();