asked on
smtp connection failedbut i tried with Gmail SMTP too it shows same error .Here is our code
<?php
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->IsHTML(false);
$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);
if(!$mail->Send())
{
echo $error_message = "Mailer Error: " . $mail->ErrorInfo;
} else
{
echo $error_message = "Successfully sent!";
}
?>