本文共 1034 字,大约阅读时间需要 3 分钟。
前几天用CI写项目用到了一个发送邮件函数,今天把它贡献出来,希望有用,什么都不说了,直接上方法
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="邮件发送失败,可能是由您的发件人或者密码填写不匹配造成"; } else { $data="邮件发送成功"; } echo $data; echo $this->email->print_debugger();}
转载于:https://blog.51cto.com/11208456/2044748