发送邮件
使用CI框架的email类库发送邮件,这里演示QQ和163
a.先去163邮件开启smtp邮件。
b.在CI的控制器里写下面的代码
$this->load->library(‘email‘); //加载CI的email类 $config[‘protocol‘] = ‘smtp‘; $config[‘smtp_host‘] = ‘smtp.163.com‘; $config[‘smtp_user‘] = ‘18367724000@163.com‘;//这里写上你的163邮箱账户 $config[‘smtp_pass‘] = ‘storecode888‘;//这里写上你的163邮箱密码 $config[‘mailtype‘] = ‘html‘; $config[‘validate‘] = true; $config[‘priority‘] = 1; $config[‘crlf‘] = "\r\n"; $config[‘smtp_port‘] = 25; $config[‘charset‘] = ‘utf-8‘; $config[‘wordwrap‘] = TRUE; $this->email->initialize($config); //以下设置Email内容 $this->email->from(‘18367724000@163.com‘, ‘mike‘); $this->email->to(‘3090333013@qq.com‘); $this->email->subject(‘Email Test‘); $this->email->message(‘<font color=red>Testing the email class.</font>‘); $this->email->attach(‘application\controllers\1.jpeg‘); //相对于index.php的路径 $this->email->send();
a.先去qq邮件开启smtp邮件。
b.在CI的控制器里写下面的代码
$this->load->library(‘email‘); //加载CI的email类 //以下设置Email参数 $config[‘protocol‘] = ‘smtp‘; $config[‘smtp_host‘] = ‘ssl://smtp.qq.com‘; $config[‘smtp_user‘] = ‘100000356@qq.com‘; $config[‘smtp_pass‘] = ‘dxwgjbziifqhbggj‘; $config[‘smtp_port‘] = ‘465‘; $config[‘charset‘] = ‘utf-8‘; $config[‘wordwrap‘] = TRUE; $config[‘mailtype‘] = ‘html‘; $config[‘newline‘] = PHP_EOL; $config[‘crlf‘] = PHP_EOL; $this->email->initialize($config); //以下设置Email内容 $this->email->from(‘18367724000@163.com‘, ‘mike‘); $this->email->to(‘3090333013@qq.com‘); $this->email->subject(‘Email Test‘); $this->email->message(‘<font color=red>Testing the email class.</font>‘); $this->email->attach(‘application\controllers\1.jpeg‘); //相对于index.php的路径 $this->email->send();
要注意先开启smtp功能才能发短信,密码是开启之后提供的,而不是邮件的登录密码。
参考资料:http://www.phpddt.com/mvc/79.html
https://www.ipbbs.net/viewtopic.php?pid=119
原文:http://www.cnblogs.com/norm/p/6248072.html