HOW TO SETUP A FORMMAIL SCRIPT

First, download the formmail script here.  The file is in a compressed format and you will need Winzip or another Zip-program to uncompress the contents. Once you have done this you will see five files.

If you look at the EXAMPLES file it will walk you through how to set up the script. We will walk you through the commonly missed items as well in this article.

The next thing to do is to log into your control panel for the site you want to put the script on. Once logged in you want to look for the path to "Sendmail". This is usually found on the left side of the screen under a section marked Server Information if you are using x2, x, xskin, bluelagoon or the moonsoon theme. The path will be something like:

Sendmail Path: /usr/sbin/sendmail

Once you have found this remember it because you will use it in just a few minutes.

Now open with notepad or a text editor the file FormMail.cgi. At the top you will see a section like this:


#!/usr/bin/perl -wT
#
# $Id: FormMail.pl,v 2.17 2002/10/10 08:00:15 nickjc Exp $
#


Scroll down until you see this:


# USER CONFIGURATION SECTION
# --------------------------
# Modify these to your own settings. You might have to
# contact your system administrator if you do not run
# your own web server. If the purpose of these
# parameters seems unclear, please see the README file.
#
BEGIN

This is the section you are going to modify. First locate the line which says:

$mailprog = '/usr/sbin/sendmail -oi -t';

It will be about 7 lines below the word "BEGIN" in the above section.

Make sure the part /usr/sbin/sendmail is the same as the Sendmail path you just looked up through your control panel. If it is the same leave this line alone. If not, then change the line to reflect what your control panel says. DO NOT remove the other characters in the line like the:

>> ' << or the >> -oi -t; <<

They are needed by the program to function.



Now look for the line right below this line:

@referers = qw(dave.org.uk 209.207.222.64 localhost);

Change this line so it is something like this:

@referers = qw(mydomain.com);

You would of course put in the domain name of the site you are going to use the formmail script on. So if you were going to use this script on a site which is fred.org the line would look like this:

@referers = qw(fred.org);


Now, look at the line right below this one:

@allow_mail_to = qw(you@your.domain some.one.else@your.domain localhost);

Replace this information between the ( ) with the email address you are going to send the formmail information to. For example, if you are going to send all information to sales@fred.org the line would look like this:

@allow_mail_to = qw(sales@fred.org);



Now, look at the line two lines below this one:

%recipient_alias = ();

This is going to be a little tricky so read carefully. You need to add something like the following to this line:

%recipient_alias = ( 'SALES' => 'sales@fred.org' );

You will replace sales@fred.org with the email address you just put in the line which starts with @allow_mail_to. This is the email address you are sending the formmail to. You must have the email address surrounded by a single quote '.

Now where it says SALES replace this word with any word you wish. You will just need to remember it because you will have to use it later. Also if the word is in all uppercase or has lowercase letters pay attention to that because Sales is a different word than SALES to the server.

Now that you have done this SAVE the file. You are done editing this. You can rename this file anything you want so long as it ends with a .pl or .cgi. Whatever you name the file make sure you watch whether you use all uppercase letters or lowercase or a mix of the two. Whatever it is you will need to use the exact same uppercase letters or lowercase letters on the server. For example:

FormMail.cgi is not the same to the server as formmail.cgi.

Now that you have saved your script you need to upload to your website. You want to place the script in the "cgi-bin" folder. When you upload (if you have a choice) upload in "text" format, not binary. If you have problems and your script won't run this might be the problem. If so try to upload only in text format with a ftp program.

Once uploaded use your ftp program to change the permissions on the file/script. Look for something like CHMOD (Unix change mode). You want to change the permissions of this file to:

755

If you don't change the permissions on the file you will receive a permission error when you attempt to run the file.

========================

Now that you have your formmail script configured, you need to place a "form" on your site which sends information to the formmail script. You usually can do this through any html programming program. Here is a sample form:

form method="post" action="/cgi-bin/FormMail.pl"

input type="hidden" name="subject" value="Sales Inquiry" /


What is your name ?
input type="text" name="name" /

What is your favorite animal ?
input type="text" name="animal" /

input type="submit" /

/form

*** See bottom note about missing < > ***


Now you need to edit your form on the web page to work with the script. Look for this line in your form:

form method="post" action="/cgi-bin/FormMail.pl

See where it says FormMail.pl? Replace this with the name of your script on the server. If you named your script formmail.cgi then put that there. (Remember to type the uppercase or lowercase letters in correctly--if you don't type it exactly as it is on the server it won't work).

Now inside the form (that is between the words form and /form put the following line:

input type="hidden" name="recipient" value="SALES"

Replace the word SALES with the word you used in this line of your script:

%recipient_alias = ( 'SALES' => 'sales@fred.org' );

What you are doing here is hiding your email address from spambots which crawl around the web looking for email addresses to send spam to. Basically what you are using is a code word on your web page which is sent to the formmail script which then knows which email address to send to the information to. You never have your email address on a web page so spambots can't find it. But you have to make sure you use the exact same word in both the web page form and in the script.

At this point you have done everything necessary to have a working script. You would just need to run the web page and run the script. You can now add in additional form boxes or text boxes to customize your form as you want it. But before we end this article let's talk about two customizations that you might find very useful.

1. Redirect

Have you ever submitted a form on a website and then you were sent to another web page which says "Thanks for you submission."? Well it is very easy to do that with this form. You just need to enter the following line with the form:

input type="hidden" name="redirect" value="http://www.fred.org/success.htm"

Basically you need to replace:

http://www.fred.org/success.htm

with the name of the web page you want the person to go to after they submit the form. It can be anything you want and you can put anything you want on that web page. You do not need to do anything to the script; you just need to put this line into the form.

2. Discovering Information about the Person Submitting the Form

This script can tell you a lot of information about the person submitting or using the formmail script. Bascially to find out what kind of browser they are using, the IP address they are from, their remote host, where they came from, etc. put this line in your web page form:

input type="hidden" name="env_report" value="REMOTE_HOST, REMOTE_ADDR, REMOTE_USER, HTTP_USER_AGENT, HTTP_FROM, HTTP_REFERER"

Now, go back to the script and make sure this line says this:

@valid_ENV = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT HTTP_FROM HTTP_REFERER);

This line is just below %recipient_alias and above @locale. Make sure whatever you have in the web page is the same in the script. This will basically add information to the bottom of your email information about the user.

3. Send a Confirmation E-Mail

To send a confirmation email to the person who submitted the form you merely need to modify a section in the script and make sure you have a line in your web page script as follows:

Put this in your form somewhere:

input name="email" type="text" id="email"


Open up the script and a few lines below the other ones you modified look for this section:

$send_confirmation_mail = 0;
$confirmation_text = <<'END_OF_CONFIRMATION';
From: you@your.com
Subject: form submission

Thank you for your form submission.

END_OF_CONFIRMATION

To send a confirmation email change the following:

Change the zero to a one in this line:

$send_confirmation_mail = 1;

Change the you@your.com in this line to reflect your email address:

From: sales@fred.org


Change the words "form submission" in this line:

Subject: form submission

to be anything you want the subject line of the email to be:

Subject: We receive your Sales Request!


Now in the line which says:

Thank you for your form submission.

You can replace this with anything you like. You can type any message you wish. Just leave a blank line above the text and below the text. So you could have something like this:

$send_confirmation_mail = 1;
$confirmation_text = <<'END_OF_CONFIRMATION';
From: sales@fred.org
Subject: We receive your Sales Request!

Thank you for your form submission. We will send out your stuff immediately. Currently we are on vacation in the Grand Caymans but we will bring back your sand soon.

If you need to reach us, please call us collect. We love phone bills so you don't have to. Whatever you need we got.

Best regards, the Sales Staff

END_OF_CONFIRMATION

That's it. Whatever you put there will be emailed to the email address the user put in the web page when they submitted the form.




:::::::::::::::::::::

IMPORTANT NOTE: On some of the web page form sections the < > were removed so you could see the code and so the article would not display the form in the article.