Author Topic: Receive an email when Google directs a visitor to your site.  (Read 4426 times)

0 Members and 1 Guest are viewing this topic.

Offline gortronTopic starter

  • Irregular
  • Posts: 24
    • View Profile
Receive an email when Google directs a visitor to your site.
« on: December 08, 2008, 01:04:17 PM »
I've received help in solving PHP problems in these forums in the past so I thought I'd give a little something back. Hopefully this is the correct forum to do so?

I wanted to receive an email when Google directs anyone to my site to tell me what keywords they have used to find my site.

A very basic and useful script, hopefully it can be of use to someone or maybe to expand on.

Code: [Select]
<?php
// Script to email you when Google refers traffic to your site.
$name=""// add your name here
$email_address=""// add your email address here
$keywords="";
$referrer=$_SERVER['HTTP_REFERER'];

if( (
stristr($referrer"google")) && (stristr($referrer"search")) ) {

parse_str($referrer$output);
$keywords=$output['q'];

$email_message="Hi $name, A visitor just arrived to your site after searching for '$keywords'. ($referrer)";

mail ("$email_address","Google referred a visitor","$email_message");

}
?>