PHPMailer and Gmail conect server error

1

I see myself in the painful obligation of coming to you for help. Even though I had already posted something about PHPMailer it turns out that now it stopped working like out of the blue. I tell you: I have the following code (I omitted the mysql query because it seems unnecessary)

<?php

date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';

require ('conexion.php');

    $nombre = "";
    $link = "";

    $serial =    $_POST['serial'];
    $marca =     $_POST['marca'];
    $localidad = $_POST['localidad'];
    $barrio =    $_POST['barrio'];
    $direccion = $_POST['direccion'];
    $mensaje =   $_POST['mensaje'];

///Consulta MySQL

    $correo_recibe = $valor['email'];

$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'ssl://smtp.gmail.com';

$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;

$mail->CharSet = 'UTF-8';

$mail->Username = "bic***@gmail.com";
$mail->Password = "*******";
$mail->setFrom('Bic****@gmail.com', 'Diana Hurtado');
$mail->addAddress($correo_recibe, 'Marcela Gomez');
$mail->Subject = '¡Alguien encontró tu bici!';
$mail->msgHTML("<!DOCTYPE html>
                <html lang='en'>
                <head>
                    <meta charset='UTF-8'>
                    <title>Título</title>
                </head>
                <body>
                    Hola! ".$nombre.", desde BiciBogotá queremos informarte que al parecer alguien ha encontrado tu bici. Éstos fueron los datos que nos proporcionó: <br>

                    Datos de la bici

                    Serial: ".$serial."<br>
                    Marca: ".$marca."<br>

                    Dónde lo encontró?

                    Localidad: ".$nombre_localidad."<br>
                    Barrio: ".$nombre_barrio."<br>
                    Direccion: ".$direccion."<br><br>


                    Mensaje adicional: ".$mensaje."<br>

                    Si este mensaje ha sido de utilidad y has recuperado tu bicicleta reportalo <a href=".$link.">¡AQUÍ!</a><br> 
                        (o copia y pega este link: ".$link."),<br>
                         de esta manera ya no aparecerá más en la sección de bicicletas perdidas de tu perfil y no tendrás problemas con lo retenes de la ciudad.

                </body>
                </html>");

if (!$mail->send()) {
    echo "Ha ocurrido un error, el mensaje no ha sido enviado: " . $mail->ErrorInfo;
} else {
    echo $mail->ErrorInfo."enviado";
}

And the error I get:

SERVER -> CLIENT: 220 smtp.gmail.com ESMTP c29sm4865365uaa.50 - gsmtp
2017-10-24 04:30:58 CLIENT -> SERVER: EHLO localhost
2017-10-24 04:30:58 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [186.155.14.49]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-10-24 04:30:58 CLIENT -> SERVER: STARTTLS
2017-10-24 04:30:58 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2017-10-24 04:30:58 CLIENT -> SERVER: QUIT
2017-10-24 04:30:59
2017-10-24 04:30:59
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

I have enabled less secure applications in Gmail, I also have the correct password and mail; I have also enabled and disabled the extension line openssl.dll from php.ini in Xampp I tried a million things even downloading cURL (as it was in an error page) I really know that PHPMailer is the most recommended to send emails and Gmail among the best servers however errors one day are corrected and the other nothing works .

Guys, I really need your help, I've been with them for quite some time. I do not know what to do anymore

Thanks in advance.

    
asked by DianaDiana 24.10.2017 в 06:46
source

3 answers

1

Guys, thank you very much for answering ... I tell you: I made too many modifications by following link and none worked for me .. Even the commands dig +short smtp.gmail.com , ping smtp.gmail.com and telnet smtp.gmail.com 587 gave successful answers. The way I see it has to do with GMail which has implemented too many restrictions for external applications so I switched to Hotmail or Outlook.

Like this:

$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.live.com';

$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;

$mail->CharSet = 'UTF-8';

$mail->Username = "****@hotmail.com";
$mail->Password = "****";
$mail->setFrom('****@hotmail.com', 'Nombre');
$mail->addAddress('****@gmail.com', 'Nombre');

And the shipment was completely successful It may not be a complete solution (for those who really want to use GMail) but at least it has got me out of trouble.

Of the best this page, I hope to have been of help.

    
answered by 30.10.2017 / 01:32
source
1

The problem is in the host property since you indicate ssl: // and it should be without the ssl protocol, as it is indicated in SMTPSecure:

<?php

date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';

require ('conexion.php');

    $nombre = "";
    $link = "";

    $serial =    $_POST['serial'];
    $marca =     $_POST['marca'];
    $localidad = $_POST['localidad'];
    $barrio =    $_POST['barrio'];
    $direccion = $_POST['direccion'];
    $mensaje =   $_POST['mensaje'];

///Consulta MySQL

    $correo_recibe = $valor['email'];

$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';

$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;

$mail->CharSet = 'UTF-8';

$mail->Username = "bic***@gmail.com";
$mail->Password = "*******";
$mail->setFrom('Bic****@gmail.com', 'Diana Hurtado');
$mail->addAddress($correo_recibe, 'Marcela Gomez');
$mail->Subject = '¡Alguien encontró tu bici!';
$mail->msgHTML("<!DOCTYPE html>
                <html lang='en'>
                <head>
                    <meta charset='UTF-8'>
                    <title>Título</title>
                </head>
                <body>
                    Hola! ".$nombre.", desde BiciBogotá queremos informarte que al parecer alguien ha encontrado tu bici. Éstos fueron los datos que nos proporcionó: <br>

                    Datos de la bici

                    Serial: ".$serial."<br>
                    Marca: ".$marca."<br>

                    Dónde lo encontró?

                    Localidad: ".$localidad."<br>
                    Barrio: ".$barrio."<br>
                    Direccion: ".$direccion."<br><br>


                    Mensaje adicional: ".$mensaje."<br>

                    Si este mensaje ha sido de utilidad y has recuperado tu bicicleta reportalo <a href=".$link.">¡AQUÍ!</a><br> 
                        (o copia y pega este link: ".$link."),<br>
                         de esta manera ya no aparecerá más en la sección de bicicletas perdidas de tu perfil y no tendrás problemas con lo retenes de la ciudad.

                </body>
                </html>");

if (!$mail->send()) {
    echo "Ha ocurrido un error, el mensaje no ha sido enviado: " . $mail->ErrorInfo;
} else {
    echo $mail->ErrorInfo."enviado";
}

I have also fixed a couple of errors, the variables that gave undefined (name_locality and name_barrio, since it exceeds "name _".

Once you run the code, it will probably give you a security error and an email will come to the gmail account where it explains how to allow connections from non-secure applications.

The only part that would be corrected would be "Name and link" that I understand you will be with it.

Greetings,

    
answered by 24.10.2017 в 11:44
0

If your code already worked. You have not edited it, you have not migrated it from the server, you have not changed the PHP version, the contrase of the account is the same.

The problem can be a DNS error, a network error, or an error in your Firewall in the firewall.

If the server of your site is linux or unix, check the access to the server from the command line with:

nslookup smtp.gmail.com

nmap -p 587 -T4 -A -v smtp.gmail.com
    
answered by 25.10.2017 в 02:57