SMTP error 'error could not authenticate' using PhpMailer

0
  

I want to know why I can not use the SMTP service with another account other than the one I originally used for testing, the error is not code since the first account works correctly, is there something I need to configure so that the Second account stop sending the message 'error could not authenticate'? Any account settings in Gmail? Already activate the permission 'Allow less secure applications to access your account', something else I should do? Any suggestions? Thanks in advance!   This is my php code

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Formulario</title> <!-- Aquí va el título de la página -->
<script type="text/javascript">
      function submitForm() {
   // Get the first form with the name
   // Hopefully there is only one, but there are more, select the correct index
   var frm = document.getElementById('form1');
   frm.submit(); // Submit
   frm.reset();  // Reset
   return false; // Prevent page refresh
}
    </script>

</head>

<body>
<?php

$Nombre = $_POST['Nombre'];
$Email = $_POST['Email'];
$Mensaje = $_POST['Mensaje'];
$Telefono = $_POST['Telefono'];    

if ($Nombre=='' || $Email=='' || $Mensaje=='' || $Telefono==''){

    echo "<script>alert('Los campos marcados con * son obligatorios');location.href ='javascript:history.back()';</script>";

}else{


    require("archivosformulario/class.phpmailer.php");
    $mail = new PHPMailer();    
    $mail->From     = $Email;
    $mail->FromName = $Nombre; 
    $mail->AddAddress("[email protected]"); // Dirección a la que llegaran los mensajes.

    // Aquí van los datos que apareceran en el correo que reciba
    //adjuntamos un archivo 

    $mail->WordWrap = 50; 
    $mail->IsHTML(true);     
    $mail->Subject  =  "Comentarios Tiendas El Golazo";
    $mail->Body     =  "Nombre: $Nombre \n<br />".    
    "Email: $Email \n<br />".    
    "Mensaje: $Mensaje \n<br />".
    "Telefono: $Telefono \n<br />";       

    // Datos del servidor SMTP

    $mail->IsSMTP(); 
    $mail->Host = "ssl://smtp.gmail.com:465";  // Servidor de Salida.
    $mail->SMTPAuth = true; 
    $mail->Username = "[email protected]";  // Correo Electrónico
    $mail->Password = "pwd"; // Contraseña

    if ($mail->Send())
    echo "<script>alert('Formulario enviado exitosamente, le responderemos lo más pronto posible.');
            location.href ='contactanos.html';
            </script>";    

    else
    echo "<script>alert('Error al enviar el formulario');location.href ='javascript:history.back()';</script>";

}

?>
</body>
</html>
  

I doubt it's code because one account does work and another does not. Help!

    
asked by Alejandro Ruiz 24.05.2016 в 22:56
source

1 answer

1

Try changing the line: $mail->Host = "ssl://smtp.gmail.com:465"; with the following:

$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 465; 
$mail->SMTPSecure = 'ssl'; 

Although the error you mention is due to the user and password, check the account credentials well to access the SMTP server.

    
answered by 25.05.2016 / 01:00
source