« Movable Type Friendly Web Hosts | Main | Colors - Experimenting With, Using MTSetVar and MTGetVar »

"Email Me" Contact Forms

Providing contact information on your weblog can be useful to your site visitors who may want to email you directly rather than submit a comment to one of your entries. You can choose to write out your email address, provide a mailto link (see MailTo Syntax for how to write out a mailto hyperlink), or you can provide a contact form. Contact forms are often preferred because they can easily hide your email address information from the spammers who regularly scour the web looking for email addresses to harvest.

I have researched and tested two free PHP-based contact form scripts - TheSiteWizard Feedback form and DodosMail - either of which you can easily implement to add a contact form to your site.

TheSiteWizard.com Feedback Form Wizard

The easiest form to implement is the SiteWizard feedback form; the php script is available at thesitewizard.com. SiteWizard also offers a Perl-based CGI script if your server does not support PHP.

Follow the directions listed to customize the feedback.php script so that it uses your email address and load the script onto your server. Set the permissions of the script to 644. You will need to create 3 html pages (or php pages if you plan to use a php include for the form) on your website to support this script: a Feedback Form page, a Thank You page, and an Error Page. An easy way to do this is to create 4 new index templates in your weblog, one each for the script, the form, the thank you, and the error page. (Make sure to uncheck the "rebuild this template automatically" checkbox if you use this method. No need to add unnecessary rebuilds.) You can also separate out the form into a .inc template module and use a PHP include (see Using PHP and MT Includes) to pull it into the form's page. This way, if you have multiple weblogs, you can use the same form, but pulled into different pages.

Here are samples of these pages that I have used. For a demo of the scripts in action, see Feedback Form Script Demo.

Feedback Form Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Me</title>
<link rel="stylesheet" href="/styles-site.css" type="text/css" />
</head>
<body>
<div id="container">
<div class="content">
<div id="center">
<h3>contact me</h3>
<ul>
<form action="feedback.php" method="post">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
<tr><td>Your name:</td><td><input type="text" name="name" size="29" /></td></tr>
<tr><td>Your email address:</td><td><input type="text" name="email" size="29" /></td></tr>
<tr>
<td colspan="2">
Message<br />
<textarea rows="15" cols="50" name="comments">
</textarea>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<input type="submit" value="Send" />&nbsp;&nbsp;<input type="reset" value="Clear" />
<br /><br />
All fields required.<br />
</td>
</tr>
</table>
</form>
</ul>
</div>
</div>
</div>
</body>
</html>

Thank You Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Contact Me</title>

<link rel="stylesheet" href="/styles-site.css" type="text/css" />
<script language=javascript>
function closeWin()
{
 window.close();
}
</script>

</head>

<body>
<div id="container">
<div class="content">
<div id="center">

<h3>contact me</h3>

<ul>
Thank you for your message.<br /><br />

<input type="button" onClick="javascript: window.close();" value="Close" />
</ul>

</div>

</div>
</div>
</body>
</html>

Error Message Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Contact Me</title>

<link rel="stylesheet" href="/styles-site.css" type="text/css" />
</head>

<body>
<div id="container">
<div class="content">
<div id="center">

<h3>contact me</h3>

<ul>
Error. You must fill out every field. <br /><br />

<input type="button" onClick="parent.location='contact.php'" value="Return to Contact Form" />

</ul>

</div>
</div>

</div>
</body>
</html>

DodosMail

A more flexible but just a little bit trickier to implement script is DodosMail from Dodo's Scripts Collection. DodosMail features include checking the sender's email address for validity, adding customized fields, and sending you the sender's info such as IP address and page referrer. The script generates its own error message and can redirect to a thankyou page that you've created.

Using DodosMail, I've created a template module with the form and used a PHP include to pull the form into the page on which the form is placed. For an example of the DodosMail script in action, see DodosMail Test.

DodosMail Form: dodos_contact.inc

<form action="dodosmail.php" method="POST">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">

<!-- these variables require customization -->
<input type="hidden" name="required_fields" value="subject,name,email,message">
<input type="hidden" name="check_email_address" value="yes">

<!-- these variables are for the auto response email sent to your sender, feel free to disable by putting a "no" in the first line -->
<input type="hidden" name="autoresponse" value="no">
<input type="hidden" name="owner_name" value="me">
<input type="hidden" name="response_subject" value="Thank you for your mail!">
<input type="hidden" name="response_mail" value="This is an auto response to let you know that I've successfully received your email sent through my email form. Thanks!">
<input type="hidden" name="font_name" value="Verdana">

<!-- if you want dodosmail to show the send info without redirection, get rid of the following -->
<input type="hidden" name="after_url" value="http://www.yourwebsite.com/thankyou.php">
<input type="hidden" name="css_file" value="http://www.yourwebsite.com/styles-site.css">

<tr><td>Your name: </td><td><input type="text" name="name" size="29"></td><br />

<tr><td>Your email address: </td><td><input type="text" name="email" size="29"></td><br />

<tr><td>Subject:</td><td><input type="text" name="subject" size="29" /></td></tr>

<tr>
<td colspan="2">Message: <br />
<textarea rows="15" cols="50" name="message">
</textarea><br /><br />
</td>
</tr>

<tr>
<td align="left" colspan="2">
<input type="submit" value="Send" />&nbsp;&nbsp;<input type="reset" value="Clear" />
<br /><br />

All fields required. A valid email address is required.<br />

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

DodosMail Pag: dodos_contact.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Contact Me</title>

<link rel="stylesheet" href="/styles-site.css" type="text/css" />
</head>

<body>
<div id="container">
<div class="content">
<div id="center">

<h3>contact me</h3>

<?
include "/home/yourserver/path/to/your/weblog/files/dodos_contact.inc";
?>

<div>

</div>
</div>
</body>
</html>

Creating a Pop-up Contact Form

Once you have created your contact form, you can easily make it into a pop-up form. Follow the directions at How to Make a Pop-up Window for using the "onclick=attribute" method. You may find you need to adjust the width and height dimensions.

Putting the Contact Form into Your Weblog Template

Alternatively to creating a popup contact form, you can place the contact form directly on a page on your weblog, that include your weblog's banner and sidebar (see http://www.learningmovabletype.com/contact.php for an example.) To do this you will need to create at least two new index templates: a contact page and a thank you page and additionally an error page if you are using the sitewizard script. The steps to doing this are similar to Creating an About Page. Use a PHP include to include the form onto the contact page. You will also need to place a copy of the script into your weblog directory (as previously mentioned one way to do this is to create a new index template containing only the script.)

Links:

Comments (10)

Arvind [TypeKey Profile Page]:

When using contact forms, one must be very aware of security. Depending on how well the form script is written, a spammer could potentially use the form to send out spam. The main thing to note with contact form scripts is how well they are written, what sort of permissions the scripts require and how the email to which the details are sent to is passed. If the email is hardcoded into the script and the only way to change it would be to hack the script then it is good, if it is passed in another way, I would not recommend that script.

I myself use http://www.surefirewebdesign.com/scripts/ Ultimate Form Mail Script which I find to be a very powerful, secure, well written script.

elise [TypeKey Profile Page]:

Arvind, I agree whole heartedly. Both of the scripts listed have the email address hard-coded into them.

Also its often wise to check with your host, if you are not running your own server, to see if they have any rules about form to mail scripts. If you are on a virtual server, with lots of other web spaces, one single instance of a poor script can mean bad server performance for all the sites there, and that will not win you any friends.

My host has a list of scripts that they will instantly disable if they detect them on your site. They also have a list of recommended scripts but unfortunatly for me they are not the ones I like!

If in doubt put in a support request - these chaps do have a lot of experience.

One way I used to use form to mail scripts was to send the mail to myself and also to my cell phone e-mail address. This would then appear on my cell phone as a short text message - brilliant for instant response back to a potential customer!

Very helpful. I am currently using a simple "mailto" and am finding that the address is getting distributed to spam lists. The form approach looks much more secure and easier for the user. I'll give it a try. Thanks.

If you don't want to go through the steps to setup a contact form, you could have a simple mailto link, just make sure you encode it using this tool http://automaticlabs.com/enkoderform/

I followed your instructions and was easily able to get the Dodosmail.php module running. I like this approach because it allows you to hide your email address inside the PHP module if you desire. Also, the PHP include approach lets you re-use the same mail form guts on other blogs without having to reinvent the thing each time. Thanks for the recommendation, Elise. This is an example of the kind of helpful information you provide that answers questions I didn't even know I should be asking!

Adam:

Does anyone know how to remove the box from around the site wizard form?

A really good Contact Email Form script which I use and doesn't let spammers get hold of addresses can be found at: http://www.stadtaus.com/en/php_scripts/formmail_script/
Hope this can help someone.

Toni [TypeKey Profile Page]:

I've had a contact form for a couple of years now and only recently am getting bombarded with spammers using my form. I implemented dodosmail.php because 1. it hides my email address, and 2. because it checks the validity of an email address. It seems it only checks the syntax of an email address, because while testing I used segf@fjil.com (a nothing address) which is what my spammers are using, and yet I still received the email. I'm wondering if there's something that will check the actual email address to see if it is "real" as opposed to "valid".

Are you having any problems with people abusing your contact form?

Toni [TypeKey Profile Page]:

I have modified the dodosmail.php mail check function to check if a domain is real and this seems to work for me.
Replace the function with this one:

function check_email($email) {
// checks proper syntax
if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ){
list($username,$domain)=split('@',$email);
if(!getmxrr ($domain,$mxhosts)){
return false;
}
return true;
}
return false;
}

Full instructions are posted on my site.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)