SMTP error 'error could not authenticate' using PhpMailer


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" "">
<html xmlns="">

<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



$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>";


    $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->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->Host = "ssl://";  // 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';

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



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

asked by Alejandro Ruiz 24.05.2016 в 22:56

1 answer


Try changing the line: $mail->Host = "ssl://"; with the following:

$mail->Host = ''; 
$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