Avatar of karthik80c
Flag for United States of America

asked on 

SMTP Connection Failed in PHP

Hi PHP Experts!

We are using GITHUB  (https://github.com/PHPMailer/PHPMailer) code to send mail via SMTP .but we have got the error as
smtp connection failed
 but i tried with Gmail SMTP too it shows same error .Here is our code

require 'PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->IsSMTP();                       // telling the class to use SMTP

$mail->SMTPDebug = 0;                  
// 0 = no output, 1 = errors and messages, 2 = messages only.

$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 

$mail->Username = "xxx";  // Gmail username
$mail->Password = "xxx";      // Gmail password

$mail->CharSet = 'UTF-8';
$mail->SetFrom ('example@gmail.com', 'Example.com Information');
$mail->AddBCC ( 'example@gmail.com', 'Example.com Sales Dep.'); 
$mail->Subject = 'TEST';
$mail->ContentType = 'text/plain'; 

$mail->Body = 'Hai TEst Mail'; 
// you may also use $mail->Body = file_get_contents('your_mail_template.html');

$mail->AddAddress ('Example@gmail.com', 'Example');     
// you may also use this format $mail->AddAddress ($recipient);

     echo   $error_message = "Mailer Error: " . $mail->ErrorInfo;
} else 
      echo  $error_message = "Successfully sent!";

Open in new window

PHPEmail Protocols

Avatar of undefined
Last Comment
Marcus Bointon

8/22/2022 - Mon