CI发送到邮箱功能(支持发送附件)

来源:互联网 发布:档案管理源码 编辑:程序博客网 时间:2024/06/10 04:21
   public function sendMail() {
                    $config['protocol']  = 'smtp';//采用smtp方式
                    
                    $config['smtp_host'] = 'smtp.126.com';
                    $config['smtp_user'] = 'mytest@126.com';//你的邮箱帐号
                    $config['smtp_pass'] = 'mytest123';//你的邮箱密码
           

                    
                    //$config['smtp_pass'] = 25;
                    $config['charset']   = 'utf-8';
                    $config['wordwrap']  = TRUE;
                    $config['mailtype']  = "html";
                    $this->load->library('email');//加载email类
                    $this->email->initialize($config);//参数配置
                    $this->email->from('lijunhua19862008@126.com', '我是发件人 陈立伟');

                    $this->email->to('my@test.com');
                    //$this->email->cc('another@another-example.com');
                    //$this->email->bcc('them@their-example.com');

                    $this->email->subject('Email Test to guijia');

                    $this->email->message('Testing the email class.');

                    $this->email->attach('static/upfile/'.$sfile.'');

                                //显示发送邮件的结果,加载到res_view.php视图文件中
                    if(!$this->email->send()){
                        $data="<font color='red' size='10px'>邮件发送失败,可能是由您的发件人或者密码填写不匹配造成</font>";
     
                    } else {
                        $data="<font color='red' size='10px'>邮件发送成功</font>";
             
                    }
                    echo $data;
                     echo $this->email->print_debugger();
            
        }