Take user in query and add variable in email

Asked

Viewed 38 times

0

I need to take the USER information from the Mysql table and send it along to the email.

How do I add together the Query to take the user table information and create the variable $usuario to include down there along with the .$newpass?

I’ve tried to ->where("email = '{$email}', usuario = '{$usuario}'"); but I did not succeed.

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;
}

1 answer

0

Apparently there’s nothing wrong with your code. The $existentEmail variable should already have the return of all columns of the table Model_usuarios with the e-mail specified.

In the code you are only treating the ID identification apparently. If you var_dump the $existentEmail variable you will probably see that it will have all the columns.

Try creating a variable with the following syntax:

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

The key name must be the column name.

  • Hello Vinicisu, thank you for commenting here on my doubt! I’m kind of new at this, I’m trying to change the code of a site I own (I consider it a simple change and they charged me nonsense to do it....) I think I did the var_dump correctly and it returned me "array(0) { }" I put the https code://hastebin.com/anuxuromik.xml on the page I retrieve the email. Is that correct?

  • @Just to confirm, the feature script you posted today works normally right? What is the structure of this 'Model_usuarios' database? You can help me try to resolve this issue, because in theory your code is correct and this return means that you have not found any user with the specified email.

  • works yes, when I type the email in the area of the site intended for that part of the code and click OK is sent an email with the new password generated by the system. What I would like to do is from the email set the user to send along with the new password (some users do not remember the username to login and say that the password recovery system does not work). The structure of the Model_usuarios is: https://hastebin.com/tapafoyeja.xml

Browser other questions tagged

You are not signed in. Login or sign up in order to post.