-1

Guys I have the code below, I'm trying everything but nothing change the error "Could not authenticate.

host, user and pass are correct;

<?php
require("PHPMailer-master/src/PHPMailer.php");
require("PHPMailer-master/src/SMTP.php");
require("PHPMailer-master/src/Exception.php");

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include("conexao.php");

if (!empty($_POST)) {
    $user = $_POST["email_usuario"];
    $query = mysqli_query($con, "SELECT email_usuario FROM tbusuarios WHERE email_usuario ='$user'");

    $rows = mysqli_num_rows($query);

    if ($rows > 0) {
        $chave = sha1(uniqid(mt_rand(), true));

        $conf = mysqli_query($con, "INSERT INTO tbrecsenha (utilizador_recuperacao, confirmacao_recuperacao, data_recuperacao) VALUES ('$user', '$chave', NOW())");

        if (mysqli_affected_rows($con) == 1) {
            $link = "https://reidaliga.com/recuperar-senha?user=$user&valid=$chave";

            $mail = new PHPMailer(true); // Passing true enables exceptions

            try {
                //Server settings
                $mail->isSMTP();
                $mail->Host = 'reidaliga.com';
                $mail->SMTPAuth = true;
                $mail->SMTPSecure = 'ssl';
                $mail->Port = 465;
                $mail->Username = 'meuemail@email.com';
                $mail->Password = '@123';

                //Recipients
                $mail->setFrom('meuemail@email.com', 'Equipe de Suporte - Meu site');
                $mail->addAddress($user);

                //Content
                $mail->isHTML(true);
                $mail->Subject = 'Suporte Meu Site | Alteração de Senha!';
                $mail->Body = "<b>E-mail automático, por gentileza não responder.</b><br><br>Ola $user,<br>Para alterar sua senha, por favor acesse o link abaixo:<br>$link<br><br><br>Em caso de dúvidas você poderá nos contatar através do email: support.br@reidaliga.com<br>Boa sorte em seus palpites!!<br><b>Equipe Rei da Liga</b><br>";

                $mail->send();
                
                echo "<script>window.alert('Um email foi enviado para: $user, caso não encontre na sua caixa de entrada, verifique seu spam');</script>";
                echo "<script>window.location.href='logout';</script>";
            } catch (Exception $e) {
                echo "Erro no envio de e-mail: {$mail->ErrorInfo}";
            }
        }
    }
}
?>

Someone could help me to identify what is wrong? This code is in prod in my server.

I tried to create a new email account, and also I checked the folders that I'm trying to open "PHPMailer". Are all ok in my server.

  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Aug 15 '23 at 23:28
  • thanks for the feedback I will work on that :) – Igor Galliardo Aug 15 '23 at 23:34
  • https://stackoverflow.com/q/3949824/1427878 covers some possible reasons. – CBroe Aug 16 '23 at 06:18
  • Does this answer your question? ["SMTP Error: Could not authenticate" in PHPMailer](https://stackoverflow.com/questions/3949824/smtp-error-could-not-authenticate-in-phpmailer) – vasquez Aug 17 '23 at 07:37

0 Answers0