I am trying to send contact form to my gmail when user submit the form, but I have not receiving any email on Gmail when I am using Gmail SMTP server, I am trying both tls with port 587 & ssl with port 465.
But when I used my server SMTP it's working properly and I also received email on my web server. Code is working on PLESK but not working on Cpanel. Code is here:
<?php
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = "**********@gmail.com";
$mail->Password = "**********";
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
$mail->AddAddress("**********@gmail.com");
$mail->Subject = "Website Contact Us Form Email";
$mail->WordWrap = 80;
$mail->Body = "User Name: ".$_POST["name"]."<br/><br/>"."User Phone Number: ".$_POST["phone"]."<br/><br/>"."User Email: ".$_POST["email"]."<br/><br/>"."User Message: ".$_POST["message"]."<br/><br/>";
if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
$mail->IsHTML(true);
if(!$mail->Send()) {
echo "<p class='error'>Problem in Sending Mail.</p>";
} else {
echo "<p class='success'>Contact Mail Sent.</p>";
}
?>