【发布时间】:2016-04-26 00:51:52
【问题描述】:
所以我对这个函数有一个小问题。
public function forgot()
{
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if($this->form_validation->run() == FALSE) {
$this->load->view('header');
$this->load->view('forgot');
$this->load->view('footer');
}
else{
$email = $this->input->post('email');
$clean = $this->security->xss_clean($email);
$userInfo = $this->user_model->getUserInfoByEmail($clean);
if(!$userInfo){
$this->session->set_flashdata('flash_message', 'Adres email nie istnieje');
redirect(site_url().'/main/login');
}
if($userInfo->status != $this->status[1]){ //if status is not approved
$this->session->set_flashdata('flash_message', 'Twoje konto nie zostało aktywowane');
redirect(site_url().'/main/login');
}
$this->load->library('email');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'email',
'smtp_pass' => 'haslo',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$token = $this->user_model->insertToken($userInfo->id);
$qstring = base64_encode($token);
$url = site_url() . '/main/reset_password/token/' . $qstring;
$link = '<a href="' . $url . '">' . $url . '</a>';
$message = '';
$message .= '<strong>Zmiana hasła</strong><br>';
$message .= '<strong>Aby dokonać zmiany hasła przejdź na podany adres:</strong> ' . $link;
$toEmail = $this->input->post('email');
$to = $toEmail;
$this->email->clear();
$this->email->from('whatever@c.com');
$this->email->to($to);
$this->email->subject('Thanks for registering');
$this->email->message($message);
if(!$this->email->send())
{
echo $this->email->print_debugger();
$this->session->set_flashdata('flash_message', 'Password reset fail.');
redirect(site_url().'/main/forgot');
}
else
{
$this->session->set_flashdata('flash_message', 'Password reset done.');
redirect(site_url().'/main/login');
}
}
}
这是我在模型中假设接收电子邮件的函数:
public function getUserInfoByEmail($email)
{
$q = $this->db->get_where('users', array('email' => $email), 1);
if($this->db->affected_rows() > 0){
$row = $q->row();
return $row;
}else{
error_log('no user found getUserInfo('.$email.')');
return false;
}
}
我在重置密码时没有错误,我收到了令牌已发送到邮件的肯定信息,但我没有收到收件箱中的任何邮件。
【问题讨论】:
-
您使用的是哪个操作系统?
-
Windows 7。问题是使用相同的设置让人们注册时,我正在接收带有令牌的邮件,但在我尝试重置密码时却没有
-
你检查过你的垃圾邮件文件夹了吗??
-
是的,垃圾邮件或收件箱中没有任何内容
标签: php forms codeigniter email