# 1 > Functions in Users Controller
In Users Controller,
add the following 'forgot' and 'emailReminder' functions
(modify the from email address to your from email address)
function forgot($key = FALSE){
$this->set('section_admin', NULL);
$this->Session->write('goingTo', false);
if (!empty($this->data)) {
if ($userInfo = $this->User->doesUserExist($this->data['User']['email'])) {
//we have a user let's write a ticket
$hash = $this->User->Ticket->generate($userInfo['User']['id']);
//Let's create an email with the hash
if ($this->emailReminder($userInfo['User']['email'], $hash)) {
$this->Session->setFlash(__('Email sent, please check your email to reset your password', TRUE));
$this->redirect('/login');
} else {
$this->Session->setFlash(__('Error; please call customer service', TRUE));
}
} else {
$this->Session->setFlash(__("No email exists", TRUE));
}
}
}
private function emailReminder($to, $hash){
$domain = Router::url("/", TRUE);
$this->set('hash', $hash);
$this->set('domain', $domain);
$subject = 'Password Reset';
$Email = new CakeEmail();
$Email->transport('smtp');
$Email->to($to);
$vars['hash'] = $hash;
$vars['domain'] = $domain;
$Email->viewVars($vars);
$Email->subject($subject);
$Email->from('your_from_email_address');
$Email->template('reset');
$Email->emailFormat('html');
$sent = $Email->send();
if ($sent) {
return TRUE;
} else {
return FALSE;
}
}