0

Excuse me, I really need some help for this code :

<?php

require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$from       = "xxx@gmail.com";
$mail       = new PHPMailer();
$mail->SMTPDebug=2;
$mail->IsSMTP(true);                             // use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth   = true;                        // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host       = "smtp.gmail.com";     // SMTP host
$mail->Port       = 587;                        // set the SMTP port
$mail->Username   = "xxx@gmail.com";  // SMTP  username
$mail->Password   = "xxx";       // SMTP password
$mail->SetFrom($from , 'Admin xxx');
$mail->Subject    = "mail title";
$mail->MsgHTML("Halo halo");

$address = "xxx@gmail.com";
$mail->AddAddress($address, $to);
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

And I get this error: 2018-06-08 01:52:09 SMTP ERROR: Failed to connect to server: Network is unreachable (101) 2018-06-08 01:52:09 SMTP connect() failed.

I have tried all of solution about this problem, but nothing happen. please, I need your help. thank you..

zen ansor
  • 1
  • 1
  • 2
  • 1
    Do you get SMTP greeting messaege when tou telnet smtp.gmail.com:587 from the same host? `telnet smtp.gmail.com 587` [Translated: Is it (your) php fault?] – AnFi Jun 08 '18 at 07:36
  • Thank you, it was connected on port 587 – zen ansor Jun 08 '18 at 08:24
  • Possible duplicate of [PEAR Mail unable to connect to Gmail SMTP, failed to connect to socket](https://stackoverflow.com/questions/45942833/pear-mail-unable-to-connect-to-gmail-smtp-failed-to-connect-to-socket) – mario Nov 13 '18 at 11:58

0 Answers0