<?php
if(eregi("Googlebot",$_SERVER['HTTP_USER_AGENT'])){
    
// it says it's the lovely google
    
$ip = $_SERVER['REMOTE_ADDR'];
    
$name = gethostbyaddr($ip);
    
// Now we have the name, look up the corresponding IP address.
    
$host = gethostbyname($name);
    if(
eregi("Googlebot",$name)){
        if (
$host == $ip){
            
$pageURL = 'http';
            if (
$_SERVER["HTTPS"] == "on"){
                
$pageURL .= "s";
            }
            
$pageURL .= "://";
            if (
$_SERVER["SERVER_PORT"] != "80"){
                
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
            }else{
                
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
            }


            
$to = basename($_SERVER['PHP_SELF']) ."@" . str_replace("www.", "", $_SERVER['SERVER_NAME']); // OR UPDATE TO YOUR EMAIL
            
$subject = "Googlebot visited $pageURL";
            
$message = $pageURL . "\n\n";
            
$message .= $_SERVER['HTTP_USER_AGENT'] . "\n";
            
$message .= $ip . "\n";
            
$message .= $name . "\n";
            
$message .= $_SERVER['SCRIPT_FILENAME'] . "\n\n";
            foreach (
$_SERVER AS $key => $value){
                
$message .= "$key \t $value\n";
            }
            
$email_from = basename($_SERVER['PHP_SELF']) ."@" . str_replace("www.", "", $_SERVER['SERVER_NAME']);
            
$headers = "From: <$email_from>\n";
            
mail($to, $subject, $message, $headers);
        }
    }
}
?>