Hi,
I've not looked at your code, but from a previous project, I think I may have a solution. This is what you do:
when someone clicks on "email this page", you are generating that form using PHP right? So, using the PHP, add a hidden form element which stores the referer:
<input type=hidden name="referer_url" value="<?php echo $HTTP_REFERER; ?>">
That way, when the form gets submitted back to $PHP_SELF, you can email the URL: $referer_url (which is the form value) instead of using $HTTP_REFERER (which will point to the PHP program itself).
hope this works!
-sridhar