I am having following problem when i run forgot page the email check if working fine, but if the email is exists the mail sent section get following error not email was sent.
User.php (controller)
public function forgot() {
// create the data object
$data = new stdClass();
// load form helper and validation library
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
if($this->form_validation->run() == FALSE) {
// Load this page with error
$this->load->view('header');
$this->load->view('user/forgot/forgot');
$this->load->view('footer');
}else{
$email = trim($this->input->post('email'));
//$clean = $this->security->xss_clean($email);
$userInfo = $this->user_model->checkUserEmail($email);
if($userInfo) {
$this->password_to_email($email, $userInfo);
$this->load->view('header');
$this->load->view('user/forgot/password_sent', array('email' => $email));
$this->load->view('footer');
} else {
$data->error = 'We cant find your email address.';
$this->load->view('header');
$this->load->view('user/forgot/forgot', $data);
$this->load->view('footer');
}
}
}
private function password_to_email($email, $firstname) { $this->load->library('email');
$from_email = "test@test.com";
$token = md5($this->config->item('salt') . $firstname);
$this->email->set_mailtype('html');
$this->email->from($from_email);
$this->email->to($email);
$this->email->message('Reset your Password');
$message = '<html><body>';
$message .= '<p>Hello '.$firstname.'</p>';
$message .= '<p>Please use following link to reset your password.<br><a href="'.base_url().'reset/reset/'.$email.'/'.$token.'"></a></p>';
$message .= '<p>Thank you!</p>';
$message .= '</body></html>';
$this->email->message($message);
$this->email->send();
}