Does anyone how can I check whether the mailserver I use is down or not with php?
+2
A:
Use Net_SMTP to make a connection to the server. It won't be perfect, but if you can't connect then it's probably down.
Ignacio Vazquez-Abrams
2010-02-24 02:28:37
I'd send a HELO and then a QUIT as well :)
gnud
2010-02-24 02:34:32
@gnud: Hah. Yes, indeed, I should've mentioned that.
Ignacio Vazquez-Abrams
2010-02-24 02:37:52
+1
A:
most mail servers are on port 25. An example using sockets
$address = gethostbyname('www.somewhere.com');
$service_port="25";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "OK.\n";
}
See the PHP docs for more.
ghostdog74
2010-02-24 02:41:23
A:
function checkSMTPService($hostname, $port)
{
// Create a socket. If we fail to create a socket return false
// This is really more to check that we are able to create a socket
// than if we are able to check the server
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($socket === false) return false;
// Now we will connect to the server. If we fail we return false.
$result = socket_connect($socket, $hostname, $port);
if($result === false) return false;
return true;
}
thenetimp
2010-02-24 04:41:06