[PHP] How to check if php mailserver is turned on?

Status
Not open for further replies.

LMC

Experienced Elementalist
Joined
Apr 13, 2009
Messages
247
Reaction score
95
Hey guys,

Ive basically set up a password reset script..
Because the script relies on sending the users emails, i would like to check if the mail server is turned on and working properly before letting people access the password reset page. Is there anyway to do this?

Thanks!

EDIT:

Ive come up with this so far, however i dont know if its the best way to do things and probs isnt resource efficent:

PHP:
if(!@mail("admin@localhost","","","From:")) {
    echo'<div class="error">Password resetting is currently disabled. Sorry for any inconvenience.</div>';
} else {
  // Allow access
} else {

Please comment on whats the best thing to do...
 
Last edited:
Ive looked at the manual and tried using fsockopen and i cant get it to work, im using the standard mercury supplied with xampp.

Please pastebin or provide your source then.
Also, which protocol are you using for mercury mail, POP3, SMTP?
If it makes it easier, you could actually modify mercury mail server to relay e-mails via your Gmail account.
 
  • Like
Reactions: LMC
Please pastebin or provide your source then.
Also, which protocol are you using for mercury mail, POP3, SMTP?
If it makes it easier, you could actually modify mercury mail server to relay e-mails via your Gmail account.

Im using SMTP. And i dont understand why i need to pastbin my source, all i neeed is script to check if the mail server is turned on or not. Thanks

This is my current working exmaple i have:

PHP:
if(!@mail("admin@localhost","","","From:")) {
    echo'<div class="error">Password resetting is currently disabled. Sorry for any inconvenience.</div>';
} else {
  // Allow access
} else {
 
I thought you said:
Ive looked at the manual and tried using fsockopen and i cant get it to work, im using the standard mercury supplied with xampp.

I was inquiring for your source for your usage of fsockopen so I can determine what is the issue here since you claimed, "I can't get it to work". If your current method is working, I suggest you stick to it. Remove the '@' prepended to the mail function however.
 
  • Like
Reactions: LMC
I thought you said:


I was inquiring for your source for your usage of fsockopen so I can determine what is the issue here since you claimed, "I can't get it to work". If your current method is working, I suggest you stick to it. Remove the '@' prepended to the mail function however.

Ok mate, thanks for your help. The @ is there to stop the mail() function showing errors if the mail server is down.
 
Doesn't really matter which mail server are you using, but what port does it use, if you know port, then you can use fsockpeopen to check if there's something running on that port.

its running on port 25, ive tried fsockopen and couldnt get it to work so i just stuck with what i currently have.. anychace you could right a snippet for me showing how itl be done?
 
Ive been using this code below to check the status of my gameserver and have changed the port to suit you, all you need to do is enter your ip or domain on line 4.

Hope this helps.

Code:
<?php
ini_set('display_errors', 'off');

$host = "Enter IP or Domain here";
$port = "25";
$fp = fsockopen($host,$port,$errno,$errstr,5);
if($fp) {
echo '<span style="color:#FFFFFF;">Server</span> <span style="color:#00FF00;">ONLINE</span>';
fclose($fp);
} else {
echo '<span style="color:#FFFFFF;">Server</span> <span style="color:#FF0000;">OFFLINE</span>';
fclose($fp);
}
flush();
?>

Note: on line 6 the number 5 is how long the script waits for a reply from the port.
 
Last edited:
  • Like
Reactions: LMC
Ive been using this code below to check the status of my gameserver and have changed the port to suit you, all you need to do is enter your ip or domain on line 4.

Hope this helps.

Code:
<?php
ini_set('display_errors', 'off');

$host = "Enter IP or Domain here";
$port = "25";
$fp = fsockopen($host,$port,$errno,$errstr,5);
if($fp) {
echo '<span style="color:#FFFFFF;">Server</span> <span style="color:#00FF00;">ONLINE</span>';
fclose($fp);
} else {
echo '<span style="color:#FFFFFF;">Server</span> <span style="color:#FF0000;">OFFLINE</span>';
fclose($fp);
}
flush();
?>

Note: on line 6 the number 5 is how long the script waits for a reply from the port.

Thanks mate, its all working now!

Thread closed.
 
Status
Not open for further replies.
Back