Hen's Teeth Network. Your source for web design, web hosting and internet consulting.

Advanced Search

FormMail: Web Form to Email CGI Script

Getting Started :: Features :: Document Downloads :: Tips :: Support Home
Need more help: send email to support@hens-teeth.net, phone (866)HENS-NET or (636)447-3030, AIM HTNSupport, or MSN-IM support@hens-teeth.net.

Getting Started

Many web sites need a form which visitors fill in to request information. The data from the form are sent via email to someone for processing. The program that handles this task is called a CGI script and it converts the web form data into an email message.

We recommend NMS FormMail. You can download it for free from SourceForge. After downloading, you will need to configure it for your server and upload it. Then you will create your HTML form so that it "calls" your copy of FormMail. This document describes the process.

Downloading FormMail

  1. Go to http://nms-cgi.sourceforge.net/
  2. Click on "Programs"
  3. Download the "compat" version in the appropriate format. Most Windows users should choose "zip archive." Only choose the other if you know what it is and know that you want it.

Configuring FormMail

Open the archive that you just downloaded and get all of the files out of it. On Windows XP, this means you simply "open" it like any other folder and copy the files to your desktop or another convenient place. Look at the EXAMPLES and README files. These document FormMail fully whereas this set of instructions is just a bare skeleton for one way to install and use FormMail on a Hen's Teeth Network web hosting account.

Follow these steps carefully.

  1. Open the actual script file, FormMail.pl, in a text editor. You can use Notepad or anything else that will not add formatting (like Word would do) to the file.
  2. Find the line that begins with $mailprog and change it to read
    $mailprog = '/usr/sbin/sendmail -oi -t';
    Note that you are changing "lib" to "sbin" in the middle of the line.
  3. Find the line that begins with @referers. Remove everything between the parentheses except "localhost" and insert your own host name, both with and without the "www". If your web site was named mycompany.com then you would configure @referers to look like this:
    @referers = qw(mycompany.com www.mycompany.com localhost);
  4. Find the line that begins with @allow_mail_to. Remove everything between the parentheses and insert the email address(es) to which you want to send the form data. Only addresses listed here can be used in your form. If you wanted to be able to send mail to both support@mycompany.com and to sales@mycompany.com then you would configure @allow_mail_to like this:
    @allow_mail_to = qw(sales@mycompany.com support@mycompany.com);
  5. Save FormMail.pl

By following these instructions carefully, you will assure that your form cannot be used to send spam to everyone in the world.

Uploading FormMail to Your Server

  1. Find the cgi-bin directory of your web server. If you have a Signature Hosting or Express Hosting account then it is located in www/cgi-bin. If you have a VPS then it may be in /usr/local/apache/cgi-bin or it may be somewhere else, depending on how you configured the virtual host.
  2. Upload FormMail.pl to the cgi-bin directory. You can use any tool that you find convenient, including FTP software, SCP software, the control panel for your account, etc. (We like WinSCP, which is secure and free.)
  3. Very Important! You must turn on the "execute" permissions for the file. How you do this will vary depending on what software you use to upload the file. You should look for, and set the permissions, so that it is something like one of these examples:
    • read, write, execute
    • rwx r-x r-x
    • 755

You must perform the last step or your script will not work!

Configuring Your Form

Edit the form on your web page. At a minimum, you will configure three things. You will set the action attribute to "call" FormMail. You will set the recipient's email address. And you will set the subject line of the email message. There are lots of other things that you can set. See the README file for a complete list.

  1. Set the action attribute of the <form> tag to
    /cgi-bin/FormMail.pl
    Be careful of the capitalization!
  2. Add a hidden field to your form. Name the field "subject" and set the value to whatever the subject line of the email messages should be, probably something like "Info request from our web site."
  3. Add a second hidden field to your form. Name the field "recipients" and set the value to be the email address where the messages should be sent. You can put more than one address in the field; just separate them with commas. Note that the address(es) must be in @allow_mail_to.

All fields on your form will be included in the email message.

Features

Not applicable.

Document Downloads

Download FormMail from here.

Tips

A few field names are special.

These two fields make it easy to hit "reply" in your email program and write back to the person who filled out the form:

  • email - if present, the email messages will come "from" this address.
  • realname - if present, this name will be in the "from" part of the email message, along with the email address.

See the "FORM CONFIGURATION" section of the README file for a complete list of special field names.

Web Design Web Hosting Internet Consulting Home