Not receiving email on Gmail using Gmail SMTP but receiving on web server using my server SMTP

nigehbanweb

Registered
Jan 11, 2020
2
0
1
Pakistan
cPanel Access Level
Website Owner
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>";
}
?>
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
No Error on Web form submit successfully on Gmail i am receiving Sign in attempt was block email.
If there was an error with sending the email, you should have a corresponding error on the server, it wouldn't necessarily be present on the web form but if you have the script setup to debug it should output this information.

The page for the PHP mailer goes into some troubleshooting steps which would be useful for you PHPMailer/PHPMailer