用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4171|回复: 6
收起左侧

[已解决] CI2.02发邮件长中文标题乱码

[复制链接]
发表于 2011-6-17 11:46:55 | 显示全部楼层 |阅读模式
本帖最后由 smartweb 于 2011-6-17 14:32 编辑

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


更改为$limit = 78 - 7 - strlen($this->charset);
也是一样长中文标题乱码。
发表于 2011-6-17 12:03:31 | 显示全部楼层
PHP复制代码
[/code]中文不能直接用php的字符串截取方法的,因為中文是2個字節,用php自帶的方法截取的話,可能漢字被截了一半,這個時候就出現亂碼了。[code=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;
    }
}
复制代码
 楼主| 发表于 2011-6-17 12:25:18 | 显示全部楼层
但我邮件内容并不是乱码。。。。。。。
发表于 2011-6-17 12:44:46 | 显示全部楼层
smartweb 发表于 2011-6-17 12:25
但我邮件内容并不是乱码。。。。。。。

這個$limit = 75 - 7 - strlen($this->charset);什麽作用的,為啥要取長度?
 楼主| 发表于 2011-6-17 13:09:11 | 显示全部楼层
解决了,根本什么也不用改。
   $config['charset'] = 'utf-8';
另外有我定义两个变量
//   $config['newline'] = "\r\n";
//$config['crlf'] = "\r\n";
这两行注掉就正常了。
发表于 2011-6-17 18:18:55 | 显示全部楼层
请问一下,你下面定义的那两个变量有啥作用呢?我没想明白!
 楼主| 发表于 2011-6-18 07:33:16 | 显示全部楼层
定义邮件必须遵守格式,手册上有,中文的用默认的就可以了。

本版积分规则