PHPMailer SMTP Error: "Network is unreachable (101)" - Suspected Hosting Block

anikdev

New Member
Messages
1
Reaction score
0
Points
1
Hello everyone,

I'm hoping to get some help with a persistent PHPMailer issue on my new contact form. I've done a lot of troubleshooting, and I'm fairly certain this is a hosting environment issue, but I'd appreciate a second opinion or confirmation.

The Goal:
I am trying to send an email from a PHP contact form using PHPMailer through Gmail's SMTP server.

The Problem & Full Error Message:
When the form is submitted, the script fails to connect to the SMTP server. I have enabled SMTP::DEBUG_SERVER in PHPMailer, and this is the complete output I receive:
2025-08-16 06:00:38 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP Error: Could not connect to SMTP host. Failed to connect to server
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server SMTP code: 101 Additional SMTP info: Network is unreachable
The key part seems to be "Network is unreachable (101)", which suggests the server can't even find a network path to smtp.gmail.com.

My send_email.php Code:
Here is the relevant part of my PHP script. (Important: I have replaced my actual email and App Password with placeholders for security.)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
// Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Debugging is enabled
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'my-email@gmail.com'; // My Gmail address
$mail->Password = 'xxxx xxxx xxxx xxxx'; // My 16-character Google App Password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

// Recipients
$mail->setFrom('my-email@gmail.com', 'My Website');
$mail->addAddress('recipient-email@example.com', 'Recipient Name');

// Content
$mail->isHTML(false);
$mail->Subject = 'Test From Contact Form';
$mail->Body = 'This is a test message.';

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
What I've Already Tried:

  • Verified Credentials: I am 100% sure the Username and Password (which is a Google App Password) are correct.
  • Checked PHPMailer Settings: The Host, Port, SMTPSecure, and SMTPAuth settings are all correct for Gmail.
  • Confirmed vendor/autoload.php Path: The script is loading PHPMailer correctly; otherwise, I would get a different error.
  • Tested Locally: This exact script works perfectly on my local computer (XAMPP/MAMP), which strongly suggests the issue is with the live server environment.
My Question & Suspicion:
Given the "Network is unreachable" error and the fact that the script works locally, my strong suspicion is that my hosting provider is blocking outbound connections on port 587.

Can anyone confirm if this is the most likely cause? Are there any other server configurations I might be missing that could cause this specific error?

My Environment:

  • Hosting Type: Free Hosting
  • Hosting Provider: x10hosting
Thank you in advance for any insights or suggestions!
 

mrburnsx

Community Advocate
Community Support
Messages
748
Reaction score
71
Points
28
External SMTP Connections are not allowed. Need to use localhost/server name of server your account is on
 
Top