I'm on Ubuntu VM.
I have this PHP
<?php
# --------------------------------------------------------------------------------
# Goal : send an email
# Run : curl 45.55.88.57/code/mail.php | php
$to = '[email protected]';
$subject = '';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I ran this :
curl 45.55.88.57/code/mail.php | php
I get this
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 176 100 176 0 0 2 0 0:01:28 0:01:00 0:00:28 45
<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>
Is my code is wrong, or is something wrong with my VM?
I don't get any emails.
dont forget to set your gmail setting. follow this tutorial for setting google smtp.
I did have this issue a couple of times and if you are in your home developing your ISP maybe blocking the port 25.
I saw that you are on the US, for example xfinity, att and others are blocking the port 25. This text is copied from their web-page Xfinity
From Xfinity page
Why is Port 25 for Email Submission Not Supported?
Email is used for important communications and Comcast wants to ensure that these
communications are as secure and as private as possible. As such,
Comcast does not support port 25 for the transmission of email by our
residential Internet customers. Much of the current use of port 25 is by
computers that have been infected by malware and are sending spam
without the knowledge of the users of those computers.
ATT is doing the same, if you google you can find a lot of forum posts on the matter.
How to test
Do a telnet against different mail servers. Ex.
telnet gmail.com 25
telnet yahoo.com 25
telnet hotmail.com 25
This will test if your outbound connection is being block. Some ISP just drop the traffic and you will get a time out error, other can route the traffic to nowhere and you will get the gateway time out. This is the usual approach to eliminate DoD attacks and over saturate the routers CPU.
You should also test your inbound connection, almost all mail servers now connect back to test if your domain is valid and match your ip address if not it is going to get drop or send to junk or spam folder. Try to telnet from the outside to your ip address. Also if you are using NAT or PAT you should also have the appropriate port mappings to your internal ip address.
For this test you can use an external server or just an online service like an nmap port scanner. https://hackertarget.com/nmap-online-port-scanner/
If not a home user/server and telnet out was working or the presumption of port 25 being block is not true.
I will check this:
1. DNS resolve nslookup google.com
and save ipv4 and ipv6 addreses
2. check IPv4 and ipv6 configurations
+ Disable ipv6 (This can also make gateway timeouts because not reaching ipv6 host and since smtp have a high timeout, gateway expires before)
3. telnet out to ipv4 address
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With