温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-16 13:20:28 来源:网络 阅读:797 作者:x旧伤 栏目:开发技术

前几天用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();
}
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI