我正在创建一个使用 Codeigniter 和 Ion Auth Library 的站点。
我已经设置了一个注册/登录/忘记密码,除了忘记密码设置的问题之外,所有这些都可以工作。
如果用户的邮箱地址使用hotmail、yahoo、gmail等,他们收到的邮件正常,可以重置密码和数据库中的数据更改。
我在 Outlook 和 Mail 中收到这封电子邮件的个人域电子邮件地址有问题,所以它看起来可能与 Exchange 有关?
我还在具有 Outlook 的计算机上启用了日志设置,并且在测试发送电子邮件时没有记录任何内容,因此它不会阻止电子邮件。
现在我有一个包含电子邮件配置设置的数组,我不确定它是否与主机、协议、标题有关?!或任何其他设置,但我将在下面提供一些我所拥有的信息。如果有人有任何信息、链接、片段或想法,这将是一个很大的帮助。
通过使用 Ion Auth,我只是将代码保留在原来的位置,并将其更改为我在配置文件中的设置:
配置
$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(
'protocol'=> 'mail',
'mailtype' => 'html',
'charset' =>'utf-8',
'smpt_host' =>'smpt.url.com',
'smpt_user'=> 'ssl://smtp.live.com',
'smtp_port' => '25',
'validate' => TRUE,
'priority' => 1
);
忘记密码控制器:
//forgot password
function forgot_password() {
$this->form_validation->set_rules('email', 'Email Address', 'required');
if ($this->form_validation->run() == false) {
//setup the input
$this->data['email'] = array('name' => 'email',
'id' => 'email',
);
if ( $this->config->item('identity', 'ion_auth') == 'username' ){
$this->data['identity_label'] = 'Username';
}else{
$this->data['identity_label'] = 'Email';
}
//set any errors and display the form
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->_render_page('forgot_password', $this->data);
}else{
// get identity for that email
$config_tables = $this->config->item('tables', 'ion_auth');
$identity = $this->db->where('email', $this->input->post('email'))->limit('1')->get($config_tables['users'])->row();
//run the forgotten password method to email an activation code to the user
$forgotten = $this->ion_auth->forgotten_password($identity->{$this->config->item('identity', 'ion_auth')});
if ($forgotten) {
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect("login", 'refresh'); //we should display a confirmation page here instead of the login page
}else{
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect("forgot_password", 'refresh');
}
}
}
function _get_csrf_nonce() {
$this->load->helper('string');
$key = random_string('alnum', 8);
$value = random_string('alnum', 20);
$this->session->set_flashdata('csrfkey', $key);
$this->session->set_flashdata('csrfvalue', $value);
return array($key => $value);
}
忘记密码的库函数:
/**
* forgotten password feature
**/
public function forgotten_password($identity) //changed $email to $identity
{
if ( $this->ion_auth_model->forgotten_password($identity) ) //changed
{
// Get user information
$user = $this->where($this->config->item('identity', 'ion_auth'), $identity)->users()->row(); //changed to get_user_by_identity from email
if ($user)
{
$data = array(
'identity' => $user->{$this->config->item('identity', 'ion_auth')},
'forgotten_password_code' => $user->forgotten_password_code
);
if(!$this->config->item('email_config', 'ion_auth'))
{
$this->set_message('forgot_password_successful');
return $data;
}
else
{
$message = $this->load->view($this->config->item('email_templates', 'ion_auth').$this->config->item('email_forgot_password', 'ion_auth'), $data, true);
$this->email->clear();
$this->email->from($this->config->item('admin_email', 'ion_auth'), $this->config->item('site_title', 'ion_auth'));
$this->email->to($user->email);
$this->email->subject($this->config->item('site_title', 'ion_auth') . ' - ' . $this->lang->line('email_forgotten_password_subject'));
$this->email->message($message);
if ($this->email->send())
{
$this->set_message('forgot_password_successful');
return TRUE;
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
}
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
}
else
{
$this->set_error('forgot_password_unsuccessful');
return FALSE;
}
}