Forum Moderators: bakedjake

Message Too Old, No Replies

Connection timed out

PHPMailer but probably a port block?

         

dstiles

3:55 pm on Mar 31, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm trying to get PHPMailer on my web server (VPS) to talk to my remote mail server. I get the response:
Connection failed.
Error #2: stream_socket_client(): unable to connect to mail.bristolweb.net:587
(Connection timed out)

I've tried this with port 25 and 587 (with appropriate changes) but it always gives the impression the call never gets outside the parent server. Incoming to 80 and 443 work fine. Ping to google works (but not to my mail server as it's not allowed). Mail server works well and has been for years. Telnet fails (but possibly would anyway - can't remember what I blocked on mail server).

I THINK it's a blocked port but can't work out how. I've been searching for a couple of days but all the likely hits return something like "Talk to your hosting service" or "it's firewall.

My iptables at present is short:
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
-A OUTPUT -j ACCEPT
# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
# Allows SSH connections
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Allow ping
# note that blocking other types of icmp packets is considered a bad idea by some
# remove -m icmp --icmp-type 8 from this line to allow all kinds of icmp:
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# log iptables denied calls (access via 'dmesg' command)
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Reject all other inbound - default deny unless explicitly allowed policy:
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT

I've added 25 and 587 as inputs and outputs but, as expected, no difference.

At one point I installed DMA (Dragonfly) smtp MTA but that couldn't connect either.

Usually I can find the answer to problems online but this has me beat. :(

lammert

4:21 pm on Mar 31, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you talk to your ISP? Many ISPs block traffic to email ports by default to prevent spam. You could also try the MTR program on your web server which traces packets and tells you where they are lost. A typical call would be:
mtr --port 25 smtp.example.com
where smtp.example.com is the name of the mail server.

graeme_p

6:16 pm on Mar 31, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have had to ask my VPS provider to unblock those ports. Its usual for them to be blocked these days so if you have never asked for them to be unblocked assme they are blocked.

dstiles

1:22 pm on Apr 1, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hosting company says not blocked.

MTR increments first and second lines - first has the hosting company's domain but second is just queries in red.

Found it!

Thanks for the sideways suggestion. :) It was a firewall problem, but on the receiving mail server, which hadn't occurred to me. I have a mechanism in place which adds IPs of certain types of smtp baddies to iptables. One of my early attempts at contact must have triggered it.

mack

1:01 am on Apr 9, 2021 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Can you ping ip.add.re.ss:port when SSH'd into the server sending the request?

Mack.

dstiles

9:30 am on Apr 9, 2021 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Already fixed thanks, mack. See previous posting.