CGI Program: generic-form-mail


A general purpose script that gathers text from an HTML form and sends it via email. This allows document owners to request feedback regarding their Web pages.

Email Address Limitation

Since March 24th, 2003 this script will only send mail to addresses in the and domains. This limit was imposed to prevent the script being used maliciously. Addresses outside those domains will be ignored. If there are no Columbia or Barnard addresses in the recipient field the script with fail and an error message will be displayed.

A Word About Mailto

Instead of using generic-form-mail you can use a mailto link to send mail as long as you don't need the added functionality of generic-form-mail. Here is an example of a mailto URL


Look here for a sample HTML form that uses generic-form-mail. After viewing it, you can save that document in your public_html directory, and edit it to replace with your address. Or, instead of using a separate document to send feedback you can insert the form in an existing document. Just copy everything from <form> to </form>, and then edit as necessary.

Scrolling Text Fields

The example uses a textarea field that allows the user to type past the right margin using many (perhaps all) of our browsers. The text will scroll to the left, allowing them to keep typing. When they hit <RETURN> the cursor moves to the next line. Mosaic and Netscape allow the user to type past the bottom margin (the text scrolls up), but Lynx does not.

The textarea field in the example is 9 lines long and 60 columns wide. You might want to display a text area of a different size, bearing in mind that Lynx does not scroll up. A smaller text area will encourage shorter messages.

As shown in the example, you can insert a salutation inside the textarea field, between the <textarea> and </textarea> tags. This is preferable to setting the salutation variable, which is described below.

Hidden Variables

The form contains hidden variables that are passed to the cgi program along with the data typed by the user. In our example we have the following:

<input type=hidden name=rmailreq value=false>
<input type=hidden name=recipient value="">
<input type=hidden name=mail_cc value="">
<input type=hidden name=cc_sender value="on">
<input type=hidden name=subject value="comments about your web page">
<input type=hidden name=ack_link value="/~aaa888/test3.html">

Set the rmailreq variable true if you want to force the user to enter their email address in the form when sending you form mail. Otherwise the email address is optional. Note that the email address will not be validated, so you can't be sure they are who they say they are. Beware of phony messages.
Set the recipient variable to your email address, so that you will receive the messages generated by this form. You can put a list of addresses here, separated by commas. The "" part is optional, since that's the default host.
Important: do not send form mail to a mailing list daemon, because the mail comes from www and you would be adding the www user to the designated mailing list. If you have any questions about this please ask the consultant.
If desired, set the mail_cc variable to the email address that should receive a CC (courtesy copy) of each message. This can be a list of addresses, separated by commas. The "" part is optional, since that's the default host.
Important: do not send form mail to a mailing list daemon, because the mail comes from www and you would be adding the www user to the designated mailing list. If you have any questions about this please ask the consultant.
Set the cc_sender variable true if you want the user to get a CC of their own message. The email address they type in the rmail field will be added to the mail_cc list, if any.
Set the subject variable to the text string that should be used as the subject of your form mail, for example: "comments about your football document". When you receive form mail from a user you will know immediately which document they are commenting on by looking at the subject. If you include the special symbol "$$" in your subject, it will be replaced with the process id of the generic-form-mail script. We use this feature to give each message a unique subject. For example "Web Comment $$" might become "Web Comment 9542" in the actual message.
A simple acknowledgement message will appear after the user sends a message with generic-form-mail. If you prefer, you can create a custom message in a separate web document, and specify the URL of that document in the ack_link variable, as shown in the example.
Each mail message sent through generic-form-mail will contain an X-URL header that specifies which web document the user sent their mail from. In many cases you would like to know which page they were looking at before the current page. You can do that using server side includes. Give your web document the "shtml" file extension instead of "html", and set the referer variable this way
<input type=hidden name=referer value=<!--#echo var="HTTP_REFERER"-->>
The salutation variable can be used to insert some text at the beginning of the message entered by the user, for example: "Dear Charlie,". A better way to specify this text is to include it in the textarea field, as shown in the example.

Text Fields

Your form must contain a textarea field called emailtext.

The rmail field should always be included, since it gives the user an opportunity to enter their email address. They can leave this field blank if you made this an optional field (that is, if you set the rmailreq variable to "false" or "").

When You Reply

When someone uses your form to send you mail you will receive an email message. In that message, the From: field will contain "www" and the Reply-To: field will contain their email address, if they typed it in the form. You should be aware that they might have typed someone else's address in that field, so beware of phony messages. When you reply to that message your mail program should automatically use the address in the Reply-To: field. Some mail programs ignore the Reply-To: field so they will send the reply to www instead of the appropriate user. If this happens to you please talk to the consultant about getting a better mail program for yourself.

If the user sends you mail without a Reply-To: field you will be unable to reply to them. Attempting to reply to those messages will send your reply to the www user, and the message will be discarded.

Last modified 12/26/06 19:41
Research and Development Group
Academic Information Systems
Columbia University
Help Line: 212 854.1919