I am getting following error: SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: test@gmail.com : Called Mail() without being connected
What is problem in my code or any other problem?
My openssl is also enable
I am doing following coding:
<?php
include("securimage/securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == true) {
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body="Name : ".$_POST['name']."<br>";
$body .="Subject : ".$_POST['subject']."<br>";
$body .="Phone : ".$_POST['phone']."<br>";
$body .="Email : ".$_POST['email']."<br>";
$body .=$_POST['comment']."<br>";
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host= "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "contactus@gmail.com";
$mail->Password = "contactus";
$mail->From = $_POST['email'];
$mail->FromName = $_POST['name'];
$mail->AddReplyTo($_POST['email']);
$mail->Subject = "Contact Us";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress('niyati@ngplweb.com', 'Niyati');
if(!$mail->Send())
{
setcookie("msg","Error.",time()+5);
header("location:contactus.php");
}
else
{
setcookie("msg","Thank you.We will get back to you soon......",time()+5);
header("location:contactus.php");
}
}
else
{
setcookie("msg","Incorrect Captcha.",time()+5);
header("location:contactus.php");
}
?>