[eluser]ibnclaudius[/eluser]
I'm creating a helper to send emails, since a I use it alot.
In this case, is to send a email to the user with the new reseted password. The password reset system works, but the email is not sent and gives a blank screen.
Code:
public function reset_password($where) {
$random_password = mt_rand(10000, 99999);
$data = array('password' => $this->CI->encrypt->sha1($random_password));
$query = $this->CI->User->update($data, $where);
if ($query) {
$email_data = array('to' => $where['email'],
'random_password' => $random_password
);
if (email_reset($email_data)) {
$this->CI->session->set_flashdata('message', 'Sua senha foi resetada e enviada para o seu email com sucesso.');
} else {
$this->CI->session->set_flashdata('message', 'Sua senha foi resetada com sucesso, mas por algum motivo não pode ser enviada para o seu email.');
}
} else {
$this->CI->session->set_flashdata('message', 'Por algum motivo não foi possível resetar sua senha.');
}
redirect('web/reset', 'location');
exit();
}
Code:
if (!function_exists('email_reset')) {
function email_reset($email_data) {
$CI =& get_instance();
$CI->load->library('email');
$CI->email->from('[email protected]', 'MeuSite');
$CI->email->to($email_data['to']);
$CI->email->subject('Sua nova senha');
$CI->email->message('Olá, sua nova senha é: ' . $email_data['random_password']);
$send = $this->email->send();
if ($send) {
return TRUE;
} else {
return FALSE;
}
}