Here is how I do it (with a bit of overkill):
function check_referrer($referrers) {
if (count($referrers)) {
$found = false;
$temp = explode("/",getenv("HTTP_referrer"));
$referrer = $temp[2];
if ($referrer == "") {
$referrer = $_SERVER['HTTP_referrer'];
list($remove, $stuff) = split('//', $referrer, 2);
list($home, $stuff) = split('/', $stuff, 2);
$referrer = $home;
}
for ($x = 0; $x < count($referrers); $x++) {
if (eregi ($referrers[$x], $referrer)) {
$found = true;
}
}
if ($referrer == "") {
$found = false;
}
if (!$found){
error_log("[Store Checkout] Illegal Referrer. (".getenv("HTTP_referrer").")", 0);
return "<div id='error'><p>You are coming from an <strong>unauthorized domain.</strong></p>\r\n"."\t<ul>\r\n".$error_list."\t</ul>\r\n"."</div>\r\n";
}
return $found;
} else {
return "<div id='error'><p>You are coming from an <strong>unauthorized domain.</strong></p>\r\n"."\t<ul>\r\n".$error_list."\t</ul>\r\n"."</div>\r\n";
}
} /* end function check_referrer */
function mail_it($content, $subject, $sender, $recipient) {
$referrers = array("example.com");
$authorizedDomain = check_referrer($referrers);
if($authorizedDomain === FALSE) {
return $authorizedDomain;
}
$sender = remove_headers($sender);
$recipient = remove_headers($recipient);
if($content !== FALSE && $subject !== FALSE && $sender !== FALSE && $recipient !== FALSE) {
$headers = "from: ".$sender."\r\n";
mail($recipient, $subject, $content, $headers);
}
return;
} /* end function mail_it */
$content = "email body content";
$subject = "email subject";
$sender = "Your Name <[email protected]>";
$recipient = $name . "<" . $email . ">";
mail_it($content, $subject, $sender, $recipient);