CI发送到邮箱功能(支持发送附件)
更新:HHH   时间:2023-1-7


前几天用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="<font color='red' size='10px'>邮件发送失败,可能是由您的发件人或者密码填写不匹配造成</font>";
  } else {
  $data="<font color='red' size='10px'>邮件发送成功</font>";
  }
  echo $data;
  echo $this->email->print_debugger();
}
返回开发技术教程...