Get user in query and add variable in email

0

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;
}
    
asked by anonymous 19.11.2018 / 14:28

1 answer

0

Apparently there is nothing wrong with your code. The variable $ existentEmail should already have the return of all columns of the Model_Usuarios table with the specified email.

In the code you are only dealing with ID identification apparently. If you give a var_dump in the variable $ existentEmail you will probably see that it will have all the columns.

Try to create a variable with the following syntax:

$usuario = $existentEmail[0]["usuario"];

The key name should be the column name.

    
19.11.2018 / 14:45