Hide Your Email Address Using PHP
To hide a mailto: link with PHP, make a PHP web page as shown here and then link to it. (Your server must, of course, be able to handle PHP pages.)
Here is the PHP web page:
<?php
header(”Location: mailto:name@example.com”);
?>
<html><body>
<h4>Thank you!</h4>
</body></html>
Replace name@example.com with the email address you would otherwise have in your regular mailto: link. Save the page as example.php or whatever other name you want for it — so long as it has a .php file name extension.
The above PHP code must be at the very top of the page — no spaces or blank lines may be above it. You may change or remove the content below the PHP code (below the “?>” line).
What happens is that the PHP sends a raw HTTP mailto: header to the browser. This causes the browser to launch the site visitor’s email program like a mailto: link would.
Note: It is possible, with certain programming, to retrieve the email address that is coded in the PHP page, provided the software knows or guesses correctly where it’s at. Therefore, it may be prudent to omit the word “mail” from within the file name (and the link text linking to the file) so crawlers have no hints.
Upload the PHP web page to your server and note its URL.
Now, in your regular web page, replace the mailto: link with a link directly to your PHP web page. When clicked, the PHP web page will open your visitor’s email program with your email address pre-filled in, just like your old mailto: link used to do.
When the link is clicked, some browsers will display a blank page instead of whatever content you put below the PHP code. If that is a concern, the link could be put into an iframe.
Here is how to put the link into an iframe:
Make a separate web page with the link. The web page might look like this:
<html>
<head>
<style type=”text/css”>
body { margin:0px; }
</style>
<head>
<body>
<a href=”http://example.com/example.php”>
Click here to write to me.
</a>
</body></html>
Now upload the page to your server and note its URL. (Let’s suppose you named the web page file “iframepage.html”)
In your original web page, replace the old mailto: link with this:
<iframe
src=”http://example.com/iframepage.html”
width=”175″
height=”25″
frameborder=”0″>
</iframe>
Adjust the width and height as necessary to display the link.
Now, when someone clicks on the link in the iframe (and the user’s email program launches), only the area of the iframe will be effected. Whether the browser displays the “Thank you” content or a blank page in the iframe, it matters little.
Copyright 2006 Bontrager Connection, LLC
Will Bontrager
Software Programmer
http://willmaster.com/master/
Reprinted with permission.