public function forgetpasswordAction() { $form2 = new Application_Form_Registration(); $form2->getElement('register')->setLabel('send'); $form2->removeElement('name'); $form2->removeElement('password'); $form2->removeElement('confirmPassword'); $form2->removeElement('image'); $form2->removeElement('room_no'); $form2->removeElement('ext'); $this->view->form = $form2; if ($this->getRequest()->isPost()) { if ($form2->isValid($this->getRequest()->getParams())) { $email = $this->_request->getParam('email'); var_dump($email); $usermodel = new Application_Model_User(); if ($userid = $usermodel->checkuserEmail($email)) { $newpassword = substr(hash('sha512', rand()), 0, 8); //////////////////// mail && password /////////////////////////// $smtpoptions = array('auth' => 'login', 'username' => '*****@*****.**', 'password' => 'Marwaspassword', 'ssl' => 'tls', 'port' => 587); $mailtransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $smtpoptions); $mail = new Zend_Mail(); $mail->addTo($email, 'to..'); $mail->setSubject('Hi'); $mail->setBodyText('your new password is ' . $newpassword); $mail->setFrom('*****@*****.**', 'Cafee Prohect'); //Send it! $sent = true; try { $mail->send($mailtransport); } catch (Exception $e) { $sent = false; } //Do stuff (display error message, log it, redirect user, etc) if ($sent) { if ($usermodel->updateuseremail(md5($newpassword), $userid[0]['id'])) { echo 'Successfully Sent Please Check your Email'; } else { echo 'Error in Server'; } } else { echo 'Failed Sending to your Email Please Check your Settings'; } } else { echo 'This Email is not Existed in my Database'; } } } }