How to resolve PHPMailer error?


I have this error when sending mail for password recovery. I attach the error:

Connection: opening to, timeout=300, options=array ( )
Connection: opened
We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SERVER -> CLIENT: 220 TLS go ahead
CLIENT: 535 Incorrect authentication data
ERROR: Password command failed: 535 Incorrect authentication data
SMTP Error: Could not authenticate
SERVER -> CLIENT: 221 closing connection
SMTP connect() failed. 

My php code is the following:

require_once 'connections/conexion.php';
require_once 'funciones/conf_email.php';

$errors = array();
if(!empty($_POST)) {
$email = mysqli_real_escape_string($ConexionBD, $_POST['recover_mail']);

if(!isEmail($email)) {
    $errors[] = "Debe ingresar un email valido";
} // end isEmail

if(emailExiste($email)) {
    //hace una consulta a la tabla cliente_correo
    $user_id       = getValor('cliente.idCliente', 'correoElectronico', $email);
    $nombreUsuario = getValor('cliente.nombre', 'correoElectronico', $email);
    $aPaterno      = getValor('cliente.apellidoPaterno', 'correoElectronico', $email);

    $url = 'http://'.$_SERVER["SERVER_NAME"].'/cliente_change-password.php?user_id='.$user_id;

    $asunto = 'Recuperar Password';
    $cuerpo2 = "
    <table width='537' height='662' border='1'>
            <td width='253' height='94'>Buen día ' $nombreUsuario $aPaterno '</td>
            <td width='557'>Has solicitado una nueva contraseña,<br>
                para proceder, haz clic a la siguiente dirección:
                <a href='$url' >Cambio de contraseña!</a>
                <td colspan='2'>
                    <img src='' width='720px' height='auto'>


    if(enviarEmail($email, $nombreUsuario, $asunto, $cuerpo2)) {
        echo "
            Hemos enviado un correo electronico a la direción
            $email para restablecer tu contraseña.
        //echo "<a href='cliente_login.php'>Iniciar sesion</a>";
        print "<script>setTimeout(7000); window.location='cliente_login.php';</script>";
    } else {
        $errors[] = "Error al enviar email";
} else {
    $errors[] = "El email no existe";
} // end POST

Now, the content of the conf_email.php library is as follows:

//enviar email al cliente
function enviarEmail($email, $nombreUsuario, $asunto, $cuerpo){
require 'php/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer();
$mail->SMTPDebug = 2; //para que me mostrara los errores, no envía el correo
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls'; // Modificar
$mail->Host = ''; // Modificar
$mail->Port = 587; // Modificar
$mail->Username = ''; // Modificar
$mail->Password = '*************'; // Modificar

$mail->setFrom(''); // Modificar REMITENTE
$mail->addAddress($email, $nombreUsuario); // DESTINATARIO

$mail->Subject = $asunto;
$mail->Body    = $cuerpo;

if($mail->send() ) {
    return true;
else {
    return false;

My html form is the following:

<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>" role="form" 
              class=" form-horizontal login-form">        
                <div class="login-wrap">
                    <p class="login-img"><i class="icon_lock_alt"></i></p>
                    <div class="input-group">
                        <span class="input-group-addon"><i class="icon_profile"></i></span>
                        <input type="email" name="recover_mail" class="form-control" 
                               placeholder="Introduce tu correo electrónico" required >
                    <label class="checkbox">
                        <span class="pull-right"> <a href="cliente_login.php"> Regresar al login</a></span>
                    <button class="btn btn-primary btn-lg btn-block" type="submit" 
                <div class="panel-footer">
                    ¿No te has registrado? <a href="cliente_registrar.php">Registrate ahora</a>

When I click the Send button, I mark that error and also does not send the email to the client to recover their password. I already modified the line:

$mail->SMTPDebug = 2; //escribo un cero (0)

But still the mail is not sent and I get the error: Error sending email.

Does anyone have any idea of ​​a solution to this error? Or at least explain to me why the email was not sent to the client.


If you're doing it from localhost, it probably won't work.

What you should do is upload it to the server so that it works for you or from localhost temporarily put:

/*$mail->SMTPDebug = 2; para que me mostrara los errores, no envía el correo
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls'; // Modificar*/
$mail->Host = 'localhost'; // Modificar
/*$mail->Port = 587; // Modificar
$mail->Username = ''; // Modificar
$mail->Password = 'EJEMPLODEPASSWORD1234'; // Modificar*/

Remember that for emails to work from localhost you have to have Mercury configured in your Xammp:

Explanatory video to configure Mercury.

Scroll to Top