Skip to content

Instantly share code, notes, and snippets.

@artlung
Created July 14, 2010 15:31
Show Gist options
  • Save artlung/475570 to your computer and use it in GitHub Desktop.
Save artlung/475570 to your computer and use it in GitHub Desktop.
Get notifications when page visited.
<?php
// add ip addresses you don't care about here
$no_mail = array(
'24.254.148.80',
'67.145.115.105',
'207.46.149.50',
);
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI';
$to_email = 'me@example.com';
if (!in_array($_SERVER['REMOTE_ADDR'], $no_mail)):
$body = $url . "\n\n". print_r($_SERVER, true);
$headers = 'From: webmaster@example.com' . "\n" .
'Reply-To: webmaster@example.com' . "\n" .
'X-Mailer: PHP/' . phpversion() . "\n";
mail($to_email,
'Email from '. url . $_SERVER['REMOTE_ADDR'],
$body
, $headers) or die("<!-- error with email -->");
print "<!-- notification sent -->";
else:
print "<!-- no notification sent -->";
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment