php - Cannot connect to SMTP host in local XAMPP
Get the solution ↓↓↓I've been working on a project on my localhost to send an email through php but i keep getting the error :SMTP Error: Could not connect to SMTP host. I'm using the PHPMailer and have gone through the troubleshooting but nothing seems to work. Here is the code:
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.sendgrid.com';
$mail->SMTPAuth = true;
$mail->Username = 'noreplyUser';
$mail->Password = '';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; /ENCRYPTION_SMTPS;*/
$mail->Port = 587; //25 - 465
$mail->setFrom('[email protected]', 'test');
$mail->addAddress('[email protected]');
$mail->isHTML(true);
$mail->Subject = 'test request';
$mail->Body = '';
$mail->AltBody = '';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Answer
Solution:
Make sure to disable firewall on your local machine. Then try different ports starting from 2525 or 465
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php_network_getaddresses: getaddrinfo failed: temporary failure in name resolution
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.