Issue sending mail via PHPMailer using gmail SMTP

Hi Team,

I am not getting any error is sending email via PHPMailer but unable to receive email in my INBOX. The same code works fine on other hosting account. I have read all the FAQ’s Knowledge base and followed the the give step’s but it did not work.

PFB - The PHPMailer code for your reference.

<?php


		date_default_timezone_set('Etc/UTC');

		if(	isset($_POST['submit'])){
			require 'assets/vendor/phpmailer/PHPMailerAutoload.php';
			$mail = new PHPMailer;
			$mail->isSMTP();
			
			
			$mail->Host='smtp.gmail.com';
			$mail->Port=587;
			$mail->SMTPAuth=true;
			$mail->SMTPSecure='tls';
			$mail->Username='doctor.pritam.kataria@gmail.com';
			$mail->Password='Password@123';
			
			$mail->setFrom($_POST['email'],$_POST['name']);
			$mail->addAddress('doctor.pritam.kataria@gmail.com');
			$mail->addReplyTo($_POST['email'],$_POST['name']);
			
			$mail->isHTML(true);
			$mail->Subject='Form Submission: '.$_POST['subject'];
			$mail->Body='<h1 align=center>Name:'.$_POST['name'].'<br>Email: '.$_POST['email'].'<br>Message: '.$_POST['msg'].'</h1>';



			if(!$mail->send()){	
				$result="Something went wrong. please try again.";
				}
				else{
				$result="Thanks! ".$_POST['name']." For contacting us we will get back soon";
				}
				}
?>



<!DOCTYPE html>
<html lang="en">

<h1> Thank you for contacting us we willl get back to you soon</h1>


</body>

</html>

So you’re using one Gmail account to send to that same Gmail account? I believe Gmail filters out those messages and only stores them in the Sent folder.

I would recommend to use a second account for the sending and see if that works.

Also, you’re using the email address filled in by the user as the From address. Most email providers are quite picky with the sending address you provide, and won’t let you send email from an address you don’t control. That’s why our official contact form example uses your own domain as the sender address, not the address enter by the visitor.

3 Likes

It did not work … Still facing the same issue.

Plz share the php mailer script which works on infinity free account with Gmail SMPT …

I have tried downloading the php mailer setup share by u on above message of GitHub account but that code have some issue with capture verification issue the image doesn’t appear…

THANKS ! IN ADVANCE.

Do we get one email account on free hosting accout at zero cost with infinityfree.com

You can’t add new email accounts on free hosting at the moment. Also, it’s infinityfree.net, and not infinityfree.com!

2 Likes

Request u to help me with the above comment

Plz try to search for it yourself first? We didn’t exactly try to hide it. It’s in an announcement post in this forum and visible on our public GitHub page:

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.