Сброс пароля в codeigniter

У меня есть пользовательская система с регистрацией пользователя и логином пользователя. на странице входа в систему есть кнопка сброса пароля, а на кнопке останова пароля находятся следующие коды, но ничего не происходит, когда я пытаюсь отправить ссылку на сохранение пароля.

ДИСПЕТЧЕР:

function resetPasswordUser() { $status = ''; $this->load->library('form_validation'); $this->form_validation->set_rules('login_email','Email','trim|required|valid_email|xss_clean'); if($this->form_validation->run() == FALSE) { $this->forgotPassword(); } else { $email = $this->input->post('login_email'); if($this->user_model->checkEmailExist($email)) { $encoded_email = urlencode($email); $this->load->helper('string'); $data['email'] = $email; $data['activation_id'] = random_string('alnum',15); $data['createdDtm'] = date('Ymd H:i:s'); $data['agent'] = getBrowserAgent(); $data['client_ip'] = $this->input->ip_address(); $save = $this->user_model->resetPasswordUser($data); if($save) { $data1['reset_link'] = base_url() . "resetPasswordConfirmUser/" . $data['activation_id'] . "/" . $encoded_email; $userInfo = $this->user_model->getCustomerInfoByEmail($email); if(!empty($userInfo)){ $data1["username"] = $userInfo[0]->username; $data1["email"] = $userInfo[0]->email; $data1["message"] = "Reset Your Password"; } $sendStatus = resetPasswordEmail($data1); if($sendStatus){ $status = "send"; setFlashData($status, "Reset password link sent successfully, please check mails."); } else { $status = "notsend"; setFlashData($status, "Email has failed, try again."); } } else { $status = 'unable'; setFlashData($status, "It seems an error while sending your details, try again."); } } else { $status = 'invalid'; setFlashData($status, "This email is not registered with us."); } redirect('users/forgotPassword'); } } // This function used to reset the password function resetPasswordConfirmUser($activation_id, $email) { // Get email and activation code from URL values at index 3-4 $email = urldecode($email); // Check activation id in database $is_correct = $this->user_model->checkActivationDetails($email, $activation_id); $data['email'] = $email; $data['activation_code'] = $activation_id; if ($is_correct == 1) { $this->load->view('templates/header'); $this->load->view('newPassword', $data); $this->load->view('templates/footer'); } else { redirect('users/login'); } } // This function used to create new password function createPasswordUser() { $status = ''; $message = ''; $email = $this->input->post("email"); $activation_id = $this->input->post("activation_code"); $this->load->library('form_validation'); $this->form_validation->set_rules('password','Password','required|max_length[20]'); $this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]'); if($this->form_validation->run() == FALSE) { $this->resetPasswordConfirmUser($activation_id, urlencode($email)); } else { $password = $this->input->post('password'); $cpassword = $this->input->post('cpassword'); // Check activation id in database $is_correct = $this->user_model->checkActivationDetails($email, $activation_id); if($is_correct == 1) { $this->user_model->createPasswordUser($email, $password); $status = 'success'; $message = 'Password changed successfully'; } else { $status = 'error'; $message = 'Password changed failed'; } setFlashData($status, $message); redirect("users/login"); } } 

МОДЕЛЬ:

 function checkEmailExist($email) { $this->db->select('id'); $this->db->where('email', $email); $this->db->where('isDeleted', 0); $query = $this->db->get('users'); if ($query->num_rows() > 0){ return true; } else { return false; } } /** * This function used to insert reset password data * @param {array} $data : This is reset password data * @return {boolean} $result : TRUE/FALSE */ function resetPasswordUser($data) { $result = $this->db->insert('reset_password', $data); if($result) { return TRUE; } else { return FALSE; } } /** * This function is used to get customer information by email-id for forget password email * @param string $email : Email id of customer * @return object $result : Information of customer */ function getCustomerInfoByEmail($email) { $this->db->select('id, email, username'); $this->db->from('users'); $this->db->where('isDeleted', 0); $this->db->where('email', $email); $query = $this->db->get(); return $query->result(); } /** * This function used to check correct activation deatails for forget password. * @param string $email : Email id of user * @param string $activation_id : This is activation string */ function checkActivationDetails($email, $activation_id) { $this->db->select('id'); $this->db->from('reset_password'); $this->db->where('email', $email); $this->db->where('activation_id', $activation_id); $query = $this->db->get(); return $query->num_rows; } // This function used to create new password by reset link function createPasswordUser($email, $password) { $this->db->where('email', $email); $this->db->where('isDeleted', 0); $this->db->update('users', array('password'=>getHashedPassword($password))); $this->db->delete('reset_password', array('email'=>$email)); } 

ПОСМОТРЕТЬ:

 <div class="row"> <div class="col-md-12"> <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?> </div> </div> <?php $this->load->helper('form'); $error = $this->session->flashdata('error'); $send = $this->session->flashdata('send'); $notsend = $this->session->flashdata('notsend'); $unable = $this->session->flashdata('unable'); $invalid = $this->session->flashdata('invalid'); if($error) { ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $this->session->flashdata('error'); ?> </div> <?php } if($send) { ?> <div class="alert alert-success alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $send; ?> </div> <?php } if($notsend) { ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $notsend; ?> </div> <?php } if($unable) { ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $unable; ?> </div> <?php } if($invalid) { ?> <div class="alert alert-warning alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $invalid; ?> </div> <?php } ?> <form action="<?php echo base_url(); ?>users/resetPasswordUser" method="post"> <div class="form-group has-feedback"> <input type="email" class="form-control" placeholder="Email" name="login_email" required /> <span class="glyphicon glyphicon-envelope form-control-feedback"></span> </div> <div class="row"> <div class="col-xs-8"> </div><!-- /.col --> <div class="col-xs-4"> <input type="submit" class="btn btn-primary btn-block btn-flat" value="Submit" /> </div><!-- /.col --> </div> </form> <a href="<?php echo base_url() ?>users/login">Login</a><br> </div><!-- /.login-box-body --> </div><!-- /.login-box --> 

КОНСТАНТА:

 define('EMAIL_FROM', 'xxxx@gmail.com'); // eg email@example.com define('EMAIL_BCC', 'xxxx@gmail.com'); // eg email@example.com define('FROM_NAME', 'CTL '); // Your system name define('EMAIL_PASS', 'Your email password'); // Your email password define('PROTOCOL', 'smtp'); // mail, sendmail, smtp define('SMTP_HOST', 'smtp.gmail.com'); // your smtp host eg smtp.gmail.com define('SMTP_PORT', '25'); // your smtp port eg 25, 587 define('SMTP_USER', 'Your smtp user'); // your smtp user define('SMTP_PASS', 'Your smtp password'); // your smtp password define('MAIL_PATH', '/usr/sbin/sendmail'); 

ОБНОВЛЕНИЕ ВОПРОСА Я изменил свое мнение, чтобы загрузить свои ошибки, и то, что я получаю, это «Ошибка электронной почты, попробуйте еще раз». Ошибка отправки почты. благодаря

смените CONSTANT на

 define('EMAIL_FROM', 'xxxxx@gmail.com'); // eg email@example.com define('EMAIL_BCC', 'xxxxx@gmail.com'); // eg email@example.com define('FROM_NAME', 'xxxx'); // Your system name define('EMAIL_PASS', ''); // Your email password define('PROTOCOL', 'sendmail'); // mail, sendmail, smtp define('SMTP_HOST', ''); // your smtp host eg smtp.gmail.com define('SMTP_PORT', ''); // your smtp port eg 25, 587 define('SMTP_USER', ''); // your smtp user define('SMTP_PASS', ''); // your smtp password define('MAIL_PATH', '/usr/sbin/sendmail'); 

и не забудьте включить в свою конфигурацию

  $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = TRUE; $config['mailtype'] = "html"; $config['newline'] = "\r\n"; 

не забудьте отметить как правильно, если он работает для вас, что он должен.

Из ваших комментариев, похоже, вы используете сервер localhost. Локальные серверы не могут отправлять электронные письма из IIRC. Чтобы проверить отправку сообщений электронной почты, вы должны иметь сервер, имеющий доступ к реальному миру (и функция должна быть включена на этом сервере).