如果我提交重置新密码到我的邮箱,CodeIgniter将不会发送邮件。但它会返回一个消息密码重置电子邮件已发送,所以它不会触发错误。 我使用的是CodeIgniter 2.1.4和IonAuth 2.5.2。
$config['use_ci_email'] = TRUE;
我已经将这个配置设置为TRUE,但仍未发送邮件。
$config['use_ci_email'] = TRUE;
我已经将这个配置设置为TRUE,但仍未发送邮件。
$config['use_ci_email'] = FALSE; // Send Email using the builtin CI email class, if false it will return the code and the identity
$config['email_config'] = array(
'mailtype' => 'html',
);
然后是'Auth.php',它是控制器文件,在其中更改一些代码,如下:
if ($forgotten)
{
// if there were no errors
// $this->session->set_flashdata('message', $this->ion_auth->messages());
// redirect("auth/login"); //we should display a confirmation page here instead of the login page
$config = [
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html'
];
$data = array(
'identity'=>$forgotten['identity'],
'forgotten_password_code' => $forgotten['forgotten_password_code'],
);
$this->load->library('email');
$this->email->initialize($config);
$this->load->helpers('url');
$this->email->set_newline("\r\n");
$this->email->from('xxx');
$this->email->to("xxx");
$this->email->subject("forgot password");
$body = $this->load->view('auth/email/forgot_password.tpl.php',$data,TRUE);
$this->email->message($body);
if ($this->email->send()) {
$this->session->set_flashdata('success','Email Send sucessfully');
return redirect('auth/login');
}
else {
echo "Email not send .....";
show_error($this->email->print_debugger());
}
}
else
{
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("auth/forgot_password");
}
我在CodeIgniter应用程序中使用配置文件
application/config/email.php
$config['protocol'] = 'mail';
$config['wordwrap'] = false;
$config['mailtype'] = 'html';
application/config/autoload.php
$autoload['libraries'] = array('lang','template', 'email','form_validation','session','encrypt','pagination','upload','database' );
在控制器中
$this->email->from(MAIL,MAIL);
$this->email->to($mailto);
$this->email->subject($text_subject);
$this->email->message($this->load->view('email/template_email',$data,TRUE));
$this->email->send();