我正在创建一个使用Codeigniter和Ion Auth Library的站点 .
我已经设置了注册/登录/忘记密码,除忘记密码设置的问题外,所有这些都有效 .
如果用户的电子邮件地址是使用hotmail,yahoo,gmail等,他们收到的电子邮件很好,可以重置密码和数据库中的数据更改 .
我在Outlook和Mail中接收此电子邮件的个人域电子邮件地址时遇到问题,所以看起来它可能与Exchange有关吗?
我还在具有Outlook的计算机上启用了日志设置,当测试发送电子邮件时,没有记录任何内容,因此它不会阻止电子邮件 .
现在我有一个带有电子邮件配置设置的数组,我不确定它是否与主机,协议, Headers 有关?!或任何其他设置,但我将在下面提供一些信息,我有什么 . 如果任何人有任何信息,链接,片段或想法,这将是一个很大的帮助 .
使用Ion Auth我只保留了代码,并将其更改为配置文件中的设置:
CONFIG
$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
);
Controller for Forgot Password :
//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);
}
Library function for Forgot Password:
/**
* 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;
}
}
2 回答
我不知道您需要的确切配置 . 无论这是我自己的 send_mail() 函数与 CI email library 一起使用 . 它可能会帮助你 . 但是我总是使用ION AUTH,我从未遇到过发送邮件的问题 .
我现在也有同样的问题 . 这是我的解决方案,基于这篇论坛帖子,这真的帮助我理解了这个错误 .
http://ellislab.com/forums/viewreply/785297/
在我的案例中,问题是我使用来自存储库的语言文件的IonAuth多语言设置 . 在德语语言文件中,您将找到'email_forgotten_password_subject'语言行的特殊字符'ü' .
Codeigniter邮件类未使用主题的配置中的编码 . 因此,specialchar编码错误,并出现smtp_mailer错误 .
我已经创建了一个文件application / libraries / MY_Email.php来挂钩使用过的主题setter方法和这个内容:
现在,Mailclass以正确的方式对主题进行编码,我们都进入周末喝一些啤酒 .
我希望我的解决方案符合您的问题 .
干杯