I have a very simple snippet of code which connects to a SMTP server using fsockopen (or alternatively stream_socket-client) that looks like this:
<?php
$url = gethostbyname("mx6.go2.pl");
echo $url;
$fp = fsockopen($url, 587, $errno, $errstr, 10);
if (!$fp) {
echo "port is closed or blocked"
} else {
echo "port is open and available";
fclose($fp);
}
?>
Unfortunately, I cannot connect to any of the standard ports like 25,587 or 2525 because my both host providers are blocking any outbound connections using those ports. (I can only connect to internal SMTP server or localhost via 25 or 587)
Is there a way to go round this problem using different code or ports (I mean programmatically and not something like installing my own server).
Cheers,
Marcin
If your provider blocks those outbound ports, there is nothing you can do about that. Those are the standard SMTP ports, so it is unlikely that the SMTP server is accepting connections on other ports. Your only hope is to either ask your provider to unblock those ports for your account, or else find an external HTTP-based proxy server to connect to on port 80 (unless your provider blocks that outbound port as well).
Why can't you use the provider's internal SMTP server? That is what you should be doing. Let it relay your messages to the other SMTP server for you. More and more, SMTP servers are being locked down nowadays to prevent spamming and other abuses, so you are likely to run into SMTP servers that do not allow you to connect directly to them even if you can reach their ports, because you are not a provider on that server's whitelist.