Simply what the title says. Want to know how to check if the connection is working and if not, what is the error. Btw the SMTP server is exchange 2007.
Show activity on this post. If you want to know if you can access the SMTP server from wherever you are running PHP, then you just need to connect to it on the appropriate port (default 25) and see if you get back a "220" code in the result. Just before fclose($f); added line fwrite($f, 'QUIT'. "\r\n"); .
To check if SMTP is working from the command line (Linux), is one critical aspect to be considered while setting up an email server. The most common way of checking SMTP from Command Line is using telnet, openssl or ncat (nc) command. It is also the most prominent way to test SMTP Relay.
If you want to know if you can access the SMTP server from wherever you are running PHP, then you just need to connect to it on the appropriate port (default 25) and see if you get back a "220" code in the result.
$f = fsockopen('smtp host', 25) ;
if ($f !== false) {
$res = fread($f, 1024) ;
if (strlen($res) > 0 && strpos($res, '220') === 0) {
echo "Success!" ;
}
else {
echo "Error: " . $res ;
}
}
fclose($f) ;
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