CodeIgniter 发送邮件
1. 在config目录中增加email.php
1 $config['charset'] = 'utf-8'; 2 $config['wordwrap'] = TRUE; 3 4 $config['protocol'] = 'smtp'; 5 $config['smtp_host'] = "smtp.163.com"; 6 $config['smtp_user'] = '用户名'; 7 $config['smtp_pass'] = '客户端密码'; 8 $config['smtp_port'] = '25'; 9 10 $config['mailtype'] = 'html';
2. 发送邮件
public function send(){ $this->load->library('email'); $this->email->from('发件人邮箱', '显示名称(可选)'); $this->email->to('收件人邮箱'); $this->email->cc('抄送人邮箱'); $this->email->bcc('密送人邮箱'); $this->email->subject('邮件主题'); $this->email->message('邮件正文,支持html'); $this->email->set_alt_message('如果使用html格式,对方不支持html时,显示的内容,如果不填写,会CI会自动将html标签去掉显示'); $result = $this->email->send(); if($result){ $data ['result'] = 'send success'; }else{ $data ['result'] = 'send failed'; } $this->template->view ( 'email/email', $data ); }