I’ve created a contact form using PHP and am using PHPmailer class for sending mail using SMTP gmail settings. The form is working fine for other mail ids, but when I tried to change the settings to send mail via SMTP gmail, am getting error message as "SMTP Error: Could not connect to SMTP host. and SMTP -> ERROR: Failed to connect to server: Connection refused (111)".. Below is the code am using…
require 'PHPMailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'mmuxhssfdrqnsowp'; // Use the App Password you generated
$mail->SMTPSecure = 'tls';
$mail->From = $_POST['email'];
$mail->FromName = $_POST['name'];
$mail->AddAddress('[email protected]', 'HR');
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->AddAttachment($path);
$mail->Subject = 'Application for Programmer Registration';
$mail->Body = $message;
$mail->SMTPDebug = 2;
Is there any mismatch in the settings to send mail using SMTP Gmail.
2
Answers
Try with below code.
@venkat I can’t post comments, that is why I’m posting this as answer. Is your code working in local? If it is working, then as you mentioned please contact the go-daddy customer support. I have faced the similar kind of issue one of projects. They enable some setting and the mail started working.
For better understanding please check the link https://kinsta.com/blog/gmail-smtp-server/
I’m using the below code, it is working for me.