Error PHPMailer

1

Hello everyone, I have a problem that according to the library's documentation my code is fine

require_once '../lib/PHPMailer/PHPMailerAutoload.php';
require_once '../autoloadIn.php';
 $cadena = "<p style='display:block;color:red;font:bold;'>Gracias por el CRM<p/>";
  $reporte = ComercialDO::listar_indicardor();
 $mail = New PHPMailer;
 $mail->isSMTP();
 $mail->SMTPDebug = 4;
 $mail->Debugoutput = 'html';
 $mail->SMTPAuth = TRUE;
 $mail->SMTPSecure = 'tls';
 $mail->Host = 'smtp.gmail.com';
 $mail->Port = 587;
 $mail->Username = '[email protected]';
 $mail->Password = 'xxxxxxx';
 $mail->setFrom('[email protected]','Administrador CRM');
 $mail->addAddress('[email protected]');
 $mail->Subject = 'Prueba Reporte';
 $mail->msgHTML($cadena.$reporte);
 if (!$mail->send()) {
echo "Erro".$mail->ErrorInfo;
}  else {
echo "Mensaje Enviado";
}

When I run it, it shows me this error

  

Connection: opening to smtp.gmail.com:587, timeout = 300, options = array ()   SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (0)   SMTP connect () failed. link   ErroSMTP connect () failed. link

As I saw your documentation of the error everything is fine but I do not know where I am doing wrong or maybe I am missing something Thanks for the help:)

    
asked by Jonathan Cunza 02.09.2016 в 19:57
source

3 answers

0

Well, the error was another I had to disable the selinux that was blocking the output clearly that I did this on my server where my application is located many thanks to all

    
answered by 02.09.2016 / 23:04
source
1

There may be several causes for this problem

  

SMTP ERROR: Failed to connect to server: php_network_getaddresses:   getaddrinfo failed: Temporary failure in name resolution (0) SMTP   connect () failed.

Ensure that SMTP exists, sometimes on the server where you have your php files you can not be reading:

smtp.gmail.com

and that the credentials are valid

 $mail->Username = '[email protected]';
 $mail->Password = 'xxxxxxx';

Also verify that the port is not blocked:

$mail->Port = 587;
    
answered by 02.09.2016 в 20:08
1

Remove the commented line:

$mail = New PHPMailer;

// $mail->isSMTP();

$mail->SMTPDebug = 4;
$mail->Debugoutput = 'html';
$mail->SMTPAuth = TRUE;

And try to add:

require 'class.smtp.php';

If you are developing and running a local server, such as Xampp, it is best to comment on that line. In production (and everything uploaded to a commercial server), it must be uncommented.

Google is unpredictable. And also enter the gmail account and enable the option to allow less secure applications: link

And of course, if Xampp runs correctly configure Mercury, and turn it on, or no email will come out. A quick guide, on YouTube: link

    
answered by 22.03.2017 в 21:30