Reduce SPAM with a PHP Contact Page

Version 1.1.0 Date 11-27-2005

If you are using version 1.0.0 of this ccontact page please replace it immediately with this one or one that performs checks against user input on the address and subject lines. Spammers are trying to use contact pages to send illegal email. This page is more secure than version 1.0.0 and there will be a version 2.0.0 of this page which will have more features to make it more secure. This page provides an ability to have someone alerted when attacks are done by spammers.

Reducing SPAM has become a important part of operating on the internet today. This document will provide a PHP contact page which webmasters can use to keep their e-mail address hidden from SPAM robots.

SPAM robots are used to crawl internet web pages and pick e-mail addresses from those web pages. Even today some SPAM crawlers can pick web addresses from pages with the e-mail embedded within javascript. Some webmasters use a graphical image to post their e-mail address on the internet but spammers could still read that manually and sell the address to SPAM lists.

Additionally, this contacts page allows webmasters to easily modify the contacts page when their e-mail address changes to reflect the new value of their e-mail address. They do not need to change multiple pages where an e-mail address may be embedded inside HTML code. One thing to remember when using the contacts page, however, is that when you reply to your readers, you are giving them your e-mail address, so only reply to those who you believe you can trust to not sell your e-mail address. Otherwise find a way to disguise your e-mail address.

Licensing

In the interest of reducing SPAM, I am granting a licence to all webmasters to use and modify this code. All I ask is for a link back to this website and the credit for the original code to be given to the Computer Technology Documentation Project.

About the pages

Two contacts pages are provided. The first contact page is a simple page with a form embedded where the user can type their e-mail, add a subject, and type their message. There is no capability to provide for web site style.

Contact Page 1 - The simpler page

This page is named contact1.txt. It has been renamed with a text file extension so you can easily view and copy it. To use it, copy and save it and rename it "contact1.php". There are four variables which can be changed in this contact page. They are:

  1. $recipient="contact@yourdomain.com"; - Change this to the e-mail address you want your website readers to use to contact you.
  2. $abusenotify="abuse@yourdomain.com"; - Change this to the e-mail address you want notified when someone tries to use your page to send spam.
  3. $subj="Website"; - This is the default subject placed in the subject line of the form.
  4. $message="Thank you."; - This is the message your readers will see after they submit your form.

Contact Page 2 - The page using a template HTML file

The second page utilizes a template file with the name "sitetemplate.html". It allows the contacts page to be adapted to the style of the website. The template file allows for PHP code substitution to be performed by the contacts page. The template file contains embedded strings which allow for the ability to include the php contact form, javascript form verification code and additional links which mainly allow the user to get back to the home page. The embedded strings are bracked both in front and behind by double exclaimation points (!) and are as follows:

This page is named contact2.txt. It has been renamed with a text file extension so you can easily view and copy it. To use it, copy and save it and rename it "contact2.php".

There are six variables which can be changed in this contact page. They are:

  1. $recipient="contact@yourdomain.com"; - Change this to the e-mail address you want your website readers to use to contact you.
  2. $abusenotify="abuse@yourdomain.com"; - Change this to the e-mail address you want notified when someone tries to use your page to send spam.
  3. $subj="Website"; - This is the default subject placed in the subject line of the form.
  4. $message="Thank you."; - This is the message your readers will see after they submit your form.
  5. $pagedescription="Webmaster Contact Page"; - This will be your page title, page decription, and page keywords.
  6. $abfilepath="/home/yourlogin/public_html"; - This is the absolute path to your HTML template page which must be named "sitetemplate.html". This path is the path to the folder your home page resides in according to your webhosting provider. It is the path from the root folder on your web hosting provider's server. You may need to check with your webhosting provider to get the correct information for this variable.

A Sample Template file

Here is a link to the sitetemplate.html sample template file. You can right click it and select "Save target as..." in Internet Explorer to download it. Its text is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Arachnophilia 3.9">
<meta name="description" content="!!description!!">
<meta name="keywords" content="!!keywords!!">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<title>!!title!!</title>
<link href="style.css" rel="stylesheet" type="text/css">
!!javascript!!
<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
</head>

<body>
<table cellspacing="0" cellpadding="0" border="0" class="main">
<tr>
<td>
<a href="/morepics/Birthdaycakeballoon.jpg" target="_blank" onMouseOver="window.status='Photos courtesy of the CTDP, Free for use' ;return true" onMouseOut="window.status='';return true"><img src="/morepics/Birthdaycakeballoon.gif" alt="Birthday Cake balloon"></a>

</td>
<td style="width: '100%'"><br>
<h1>!!title!!</h1>
</td>
<td>
<a href="/morepics/purplepeopleeaterfromside.jpg" target="_blank" onMouseOver="window.status='Photos courtesy of the CTDP, Free for use' ;return true" onMouseOut="window.status='';return true"><img src="/morepics/purplepeopleeaterfromside.gif" alt="Purple people eater balloon from the side"></a>

</td>
</tr>
</table>

<table class="bg">
<tr>
<td class="left">
<div class="center">
<img src="/gifs/ctdp1.gif" alt="CTDP">
</div>
!!linkscontent!!

</td>
<td class="middle">
<table class="bg">
<tr><td>
<hr class="half">
<div class="center">!!horizlinks!!</div>
<hr class="half">
</td></tr>
</table>
!!content!!
</td>

<td class="right" width="25%">
</td>
</tr>
</table>
</body>
</html>

To use the contact page 2 and the sample template file:

  1. Create a template file which matches the style of your site. Name it "sitetemplate.html".
  2. Place the exclaimation point embedded strings in your template file at the appropriate locations similar to the example shown.
  3. Download the contact page and name it "contact2.php".
  4. Change the at least two variables in your contacts page (contact2.php) to match your site settings.
    1. $recipient - Must match your e-mail address.
    2. $abfilepath - Must match the path to the folder your contacts page is in when seen from the root directory of your web hosting provider's server.

One feature that I could add to this page is an ability to display some graphic text which must be typed in by a user to use this page. This would prevent a SPAM robot from automatically using the page to send you e-mail. If anyone wants this feature, please feel free to use our contacts page to send the request to the webmaster.

Author: Mark Allen
PHP Section | Independent Section | Home