You can modify this to fit your needs. It is from my page. So I know it works. Make an if statement and if it is TRUE then run this script, have the else show your error message.
<?
if (getenv ("HTTP_X_FORWARDED_FOR")) {
$ip = getenv ("HTTP_X_FORWARDED_FOR");
} else {
$ip = getenv ("REMOTE_ADDR");
}
$lastline = exec( "ping $ip", $resultsArray );
for($i=0; $i < sizeof($resultsArray); $i++)
{
echo $resultsArray[$i] . '<br>';
}
//mail function
$to = "useremail@whatverdomain.extension"
$subject = "Message From $from Via website";
$mailheaders = "From: $from <> \n";
$body = "IP: $ip \n\n body goes here";
mail($to, $subject, $body, $mailheaders);
?>