2

Hello i create code for send to email using php mailer in localhost but i have a problem, this error is : Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

This is my code

<?php 
require_once('mailer/class.phpmailer.php');
require_once('mailer/PHPMailerAutoload.php');

        $from_email      = "gumay0838@gmail.com";
        $from_email_pwd  = "qwerty147";
        $from_email_name = "Gumay";
        $to_email        = "bedhoel.inc@gmail.com";

$mail             = new PHPMailer();
$body             = 'Hello World';
$body             = eregi_replace("[\]",'',$body);                  

$mail->IsSMTP();                                         // telling the class to use SMTP
$mail->SMTPAuth   = true;                                // enable SMTP authentication
$mail->SMTPSecure = "tls";                               // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";                    // sets GMAIL as the SMTP server
$mail->Port       = 587;                                 // set the SMTP port for the GMAIL server
$mail->Username   = $from_email;                         // GMAIL username
$mail->Password   = $from_email_pwd;                     // GMAIL password

$mail->SetFrom($from_email, $from_email_name);

$mail->Subject    = "Testing Mail";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAddress($to_email, $from_email);

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
   ?>

Note :

im already active extension=php_openssl.dll in php.ini

and already restart my xampp and already setting my gmail to Allow less secure apps: ON

Maestro Vladimir
  • 1,186
  • 4
  • 18
  • 38

0 Answers0