【发布时间】:2013-01-31 09:27:51
【问题描述】:
我正在创建一个使用 Codeigniter 和 Ion Auth Library 的网站。
我已经设置了一个注册/登录/忘记密码,除了忘记密码设置的问题之外,所有这些都可以工作。
如果用户的邮箱使用hotmail、yahoo、gmail等,他们收到的邮件正常,可以重置密码和数据库中的数据更改。
我的个人域电子邮件地址在 Outlook 和 Mail 中接收此电子邮件时遇到问题,因此看起来可能与 Exchange 有关?
我还启用了具有 Outlook 的计算机上的日志设置,并且在测试发送电子邮件时没有记录任何内容,因此它不会阻止电子邮件。
现在我有一个包含电子邮件配置设置的数组,我不确定它是否与主机、协议、标题有关?!或任何其他设置,但我将在下面提供一些我所拥有的信息。如果有人有任何信息、链接、sn-ps 或想法,这将是一个很大的帮助。
使用 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;
}
}
【问题讨论】:
-
您查看过 host.url.com 上的电子邮件日志吗?您是否使用 live 发送电子邮件?如果是这样,您是否可以先访问开发邮件服务器进行测试? -
我目前正在本地主机上开发,也上传到服务器上,但没有收到相关信息。调试时,它说电子邮件已发送,但说电子邮件可能无法读取 MIME 编码的电子邮件 - 不确定这是否可以在我的配置文件中更改?还尝试了纯文本,将所有内容都删除,但仍然没有运气甚至错误。我使用过@hotmail.co.uk,并且在 Outlook Live 浏览器、gmail 浏览器和 yahoo 浏览器中收到了电子邮件。不幸的是,我无法访问开发邮件服务器。
-
可以先在本地安装hMail Server之类的东西来测试本地发送邮件吗?您确实可以查看邮件服务器的实际日志。
-
我仅限于我可以安装的内容以及公司限制和访问范围内的位置。我尝试打开 Mail 的库/脚本文件,但我无权访问它。在另一台使用 Windows 的计算机上,我启用了日志系统,但没有任何显示...试图尽可能地缩小范围,但现在碰壁了。
-
本地开发时发送邮件,可以使用gmail
$config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'whatever@gmail.com', 'smtp_pass' => '', );
标签: php codeigniter email ion-auth