smartweb 发表于 2011-6-17 11:46:55

CI2.02发邮件长中文标题乱码

本帖最后由 smartweb 于 2011-6-17 14:32 编辑

CI2.02发邮件长中文标题乱码mail.php中
$limit = 75 - 7 - strlen($this->charset);


更改为$limit = 78 - 7 - strlen($this->charset);
也是一样长中文标题乱码。

wssx 发表于 2011-6-17 12:03:31

中文不能直接用php的字符串截取方法的,因為中文是2個字節,用php自帶的方法截取的話,可能漢字被截了一半,這個時候就出現亂碼了。/**
* 截取字符串
*/
if(!function_exists('mbSubstr')) {
    function mbSubstr($str, $sublen)
    {
      if(strlen($str)<=$sublen) {
            $rStr =$str;
      } else {
            $I = 0;
            while ($I<$sublen) {
                $StringTMP = substr($str,$I,1);
               
                if (ord($StringTMP)>=224) {
                  $StringTMP = substr($str,$I,3);
                  $I = $I + 3;
                } elseif (ord($StringTMP)>=192) {
                  $StringTMP = substr($str,$I,2);
                  $I = $I + 2;
                } else {
                  $I = $I + 1;
                }
               
                $StringLast[] = $StringTMP;
            }
            
            $rStr = implode("",$StringLast);
      }
      
      return $rStr;
    }
}

smartweb 发表于 2011-6-17 12:25:18

但我邮件内容并不是乱码。。。。。。。

wssx 发表于 2011-6-17 12:44:46

smartweb 发表于 2011-6-17 12:25 static/image/common/back.gif
但我邮件内容并不是乱码。。。。。。。

這個$limit = 75 - 7 - strlen($this->charset);什麽作用的,為啥要取長度?

smartweb 发表于 2011-6-17 13:09:11

解决了,根本什么也不用改。
   $config['charset'] = 'utf-8';
另外有我定义两个变量
//   $config['newline'] = "\r\n";
//$config['crlf'] = "\r\n";
这两行注掉就正常了。

xushre 发表于 2011-6-17 18:18:55

请问一下,你下面定义的那两个变量有啥作用呢?我没想明白!

smartweb 发表于 2011-6-18 07:33:16

定义邮件必须遵守格式,手册上有,中文的用默认的就可以了。
页: [1]
查看完整版本: CI2.02发邮件长中文标题乱码