• PHP CI框架email类发送邮件


    用CI框架发送邮件类 在中文标题太长的情况下会出现乱码,搜索后说是发送邮件的时候有标题长度的限制,按说的方法修改后,还是没能得到解决,后来发现需要转换邮件标题的编码,解决方法如下:

    打开 libraries/Email.php  找到:function subject($subject)

    public function subject($subject) 
    { 
        $subject = $this->_prep_q_encoding($subject); 
        $this->_set_header('Subject', $subject); 
        return $this; 
    } 

    修改为

    public function subject($subject) 
    { 
        //$subject = $this->_prep_q_encoding($subject); 
        $subject = '=?'. $this->charset .'?B?'. base64_encode($subject) .'?='; 
        $this->_set_header('Subject', $subject); 
        return $this; 
    } 

    代码为

    function mail(){ 
            $this->load->library('email'); 
            $config['protocol'] = 'smtp'; 
            $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
            $config['smtp_user'] = 'XXXXXXXXXX@gmail.com'; 
            $config['smtp_pass'] = 'XXXXXXXXXXXXX'; 
            $config['smtp_port'] = '465'; 
            $config['smtp_timeout'] = '5'; 
            $config['newline'] = "
    "; 
            $config['crlf'] = "
    "; 
            $this->email->initialize($config); 
             
            $this->email->from('XXXXXXXXXX@gmail.com'); 
            $this->email->to('123123123123@qq.com'); 
            $this->email->subject("北极bear北极bear北极bear北极bear北极bear北极bear北极bear北极bear北极bear北极bear北极bear"); 
            $this->email->message('哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈'); 
            $this->email->send(); 
             
            echo $this->email->print_debugger(); 
       } 

    上面的解决方案,我将CI默认的对邮件标题(Subject)的编码方式从 Q-Encoding (简称 Q编码)变成了 Base64 (简称 B编码),希望能对大家有所帮助。如有问题欢迎留言讨论。

    转自http://www.it300.com/article-8047.html

  • 相关阅读:
    [loj3364]植物比较
    [loj3366]嘉年华奖券
    [atARC105F]Lights Out on Connected Graph
    [atARC105D]Let's Play Nim
    [atARC058F]Lroha Loves Strings
    [loj3347]有趣的旅途
    [atAGC001F]Wide Swap
    [cf1392I]Kevin and Grid
    [loj3340]命运
    [loj3046]语言
  • 原文地址:https://www.cnblogs.com/feiwu123/p/5379373.html
Copyright © 2020-2023  润新知