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

使用email类,发送邮件中文乱码

[复制链接]
发表于 2009-6-22 10:48:46 | 显示全部楼层 |阅读模式
配置中
$config['charset'] = 'gbk';已经设置为中文编码

但收到的邮件还是标题或者内容乱码??
发表于 2009-6-22 11:30:31 | 显示全部楼层
换其他编码试试
 楼主| 发表于 2009-6-22 11:36:19 | 显示全部楼层
gbk,gb2312,网易邮箱等正常,139邮箱内容乱码
utf-8,标题正常,内容乱码
发表于 2009-6-30 17:00:27 | 显示全部楼层
如果项目是utf-8编码的话,这一项参数($config['charset'] =)可以不指定,默认好像就是utf-8编码。我就是这么用的,没有出现乱码问题。用的是网易和QQ邮箱,都很正常。
发表于 2009-7-15 17:03:27 | 显示全部楼层
本帖最后由 lichaoying 于 2009-7-15 17:10 编辑

以下是我发送邮件的function,相信对你有用:
PHP复制代码
 
function sendmail(){
       $config = Array(
             'protocol' => 'smtp',
              'smtp_host' => 'mail.yncmcc.cn',
              'smtp_port' => 25,
             'smtp_user' => 'lichao',
                 'smtp_pass' => '123',
                  'charset' => 'gb2312',
             'mailtype' => 'html',
         );
      // $config_ssl = Array(
          // 'protocol' => 'smtp',
          //  'smtp_host' => 'ssl://smtp.gmail.com',
          //  'smtp_port' => '465',
          // 'smtp_user' => '123@gmail.com',
          //  'smtp_pass' => '123',
          //  'mailtype' => 'html',
     //    );
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        $from_name = "电路调单";//发件人名称
        $email_subject ="调单";
        $email_msg="<br>你好!请注意查收!";
        //解决乱码问题
        $from_name = iconv('UTF-8','GB2312',$from_name);
        $email_subject = iconv('UTF-8','GB2312',$email_subject);
        $email_msg = iconv('UTF-8','GB2312',$email_msg);
        //封装发送信息
        $this->email->from('lichao@chinamobile.com',$from_name);
        $this->email->to('lichao@chinamobile.com');
        $this->email->subject($email_subject);
        $this->email->message($email_msg);
        $this->email->attach("attachments/2009/01/1.xls");//附件
        //发送
       if (!$this->email->send())
        {
            show_error($this->email->print_debugger());
            return false;
        }
        else
        {
            echo"发送成功!";
            return true;
        }
   }
 
复制代码

本版积分规则