I Need Help : Failed to connect to server: Network is unreachable SMTP

soqrat

Verified User
Joined
Mar 10, 2020
Messages
6
Hi guys,
I use the latest version directly and send mail via gmail.
I installed plesk to try on the same server and mail went fine.
I installed Directadmin and try again, mail is not going.
Error: SMTP -> ERROR: Could not connect to server: Network cannot be accessed (101)

PHP:
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->SetLanguage("tr", "phpmailer/language");
$mail->CharSet  ="utf-8";
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->SetFrom("[email protected]", "Name Surname");
$mail->AddAddress("[email protected]");
$mail->Subject = "M Title";
$mail->Body = "Message";
if(!$mail->Send()){
    echo "Error : ".$mail->ErrorInfo;
} else {
    echo "Okk";
}
 
Maybe outbound port 465 is blocked then? Try disabling CSF firewall to make sure it's not related.
 
I tried this, making it completely passive but still getting the same error.

Try this from the server:
Code:
telnet smtp.gmail.com 465

If it does not work - please try contacting your datacenter, as it's likely an external firewall.
 
Try this from the server:
Code:
telnet smtp.gmail.com 465

If it does not work - please try contacting your datacenter, as it's likely an external firewall.

Code:
[root@tr ~]# telnet smtp.gmail.com 465
Trying 64.233.184.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
Connection closed by foreign host.
 
Code:
[root@tr ~]# telnet smtp.gmail.com 465
Trying 64.233.184.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
Connection closed by foreign host.
It works from the server. So, it must be CSF not disabled (and still disallowing it from your end-customer (you can SSH as him to check)), or some misconfiguration on PHP side.
 
I don't know for sure, it says port 25 for scripts but maybe it also works for port 465 and since you're using a script try this:
SMTP_ALLOWLOCAL = "1"
in CSF.

Or disable csf totally so everything is open and see if it works then. If yes, you can be sure it's a csf setting, if not, must be a misconfiguration.
 
Firewall is completely closed but it still doesn't work. I reinstalled a few times but the result is the same.

I'm setting up Plesk working there. I couldn't find any results.
 
https://forum.directadmin.com/threa...is-unreachable-smtp-connection-refused.63606/
My solution that work for me.


1619775308062.png
 
Connection refused (111)/Network is unreachable (101) error can also occur if your web host simply doesn't allow external SMTP connection. ... So if you are on a GoDaddy server and having this issue your SMTP configuration should look like the following: SMTP Host/Server: relay-hosting.secureserver.net. Port: 25. forpc jfi.cam/jiofilocalhtml/
 
if your web host simply doesn't allow external SMTP connection.
In that case it wouldn't work on Plesk either. But he said it's working with Plesk so it must be another issue.

However, you and @shiroamada are both answering to a topic of over a year old. It will be fixed in the mean time, so please don't reply solutions to such old posts.
Also, it's not really a good idea to put a username in the "smtp_allowuser" unless maybe you only have one user. If you need that, you have set something else not correct.
 
Back
Top