I need to get the USER information from the MySQL table and send it to the email.
How do I add next to Query to get the information from the user table and create the variable $usuario
to include down there along with .$newpass
?
I have tried ->where("email = '{$email}', usuario = '{$usuario}'");
but I have not been successful.
The site is made in CodeIgniter.
public function generateNewPass()
{
$email = $_POST["email"];
$Query = Doctrine_Query::create()->from("Model_Usuarios f")
->where("email = '{$email}'");
$existentEmail = $Query->execute(null,Doctrine_Core::HYDRATE_ARRAY);
$response = array();
if(empty($existentEmail)){
$response["error"] = "y";
$response["message"] = "E-mail não cadastrado.";
echo json_encode($response);exit;
}
$newPass = $this->generatePassword();
$table = DoctrineLib::gettable("Model_Usuarios");
$mUser = $table->findOneById($existentEmail[0]["id"]);
$mUser->senha = sha1($newPass);
$mUser->save();
//Altera senha do servidor, mesmo não logado no sistema
$Planos = new Planos(true);
$Planos->getUser($existentEmail[0]["id"]);
$Planos->getServer();
if ($Planos->hasServer()){
$Planos->updateUser($newPass);
}
$response["error"] = "n";
$response["message"] = "Erro ao recuperar senha, por favor contate o suporte.";
if($this->sendNewPassMail($newPass, $email)){
$response["error"] = "n";
$response["message"] = "Uma nova senha foi enviada para " . $email;
}
echo json_encode($response);
}
private function sendNewPassMail($newPass, $email){
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.xxx.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('[email protected]', 'xxx');
$this->email->to($email);
$this->email->subject(' Senha de acesso');
$this->email->message("Sua nova senha de acesso - ".$newPass);
if($this->email->send()){
return true;
}
return false;
}