Yale University Library

 

Workstation and Technology Services

Quick Links
Creating forms using CGI mail 1.6

CGIMail is used to take the input of WWW forms and convert them to a user defined e-mail format.
Creating a CGImail form is a three step process.

Step one: Create an E-mail template that will be mailed to you when the user submits the form.

Step two: Create a WWW form that the end user will use to fill in the information.

Step three (optional): Create an alternate success page that the users will see after they submit the form.

Advanced options

Step One: Create an E-mail template.

Before you start receiving e-mail messages through the web, you should decide what these messages should look like. Create an ASCII file, called an e-mail template, that looks something like this:

To: strangeman@chasm.big  
Subject: questions three  
From: [email_address]  
   
What is your name? [yourname]  
What is your quest? [quest]  
What is your favorite color? [color]  

Header Lines*

Line 1: The To: line contains the address of the person** that the message will be mailed to.

Line 2: The Subject: line contains the subject of that message. Making this as descriptive as possible will make it easier to sort through the mail that is received. All mail received through CGImail will show it comes from "E-mail from Web Server----------" so other than the Subject: line there is no way to distinguish E-mail between different forms.

Line 3: The From: line (optional) If you ask the user to enter their email address on the WWWform you can use this information to create a valid From: line which will show you the users real e-mail address in your in box as well as allow you to use reply to respond to a message.

Line 4: Blank Line - If you want a blank line anywhere in your E-mail response just add a carriage return.

Lines 5-7: Body - The body of the message is the area that the users responses will be shown. The text of your message can be worded and formatted any way you like. The only constant must be that the names in the brackets [ ] are identical to the names on your WWW form. Also, names are case sensitive so it is recommend you use lower case only.

* It is mandatory that the TO: and SUBJECT: lines are the first two lines in the form.
** If you would like to have the message sent to multiple recipients separate each E-mail address with a space
     (i.e. To: george.ouellette@yale.edu karen.reardon@yale.edu).

This file must be saved as a text file. If you created it using MS Word or other commercial word processing program be sure to select "save as" and choose text file (.txt)

Back to top   View an example


Step Two: Create a WWW form.

The WWW form is formatted as follows:

<form method="post" action"http://www.library.yale.edu/cgi-bin/cgiemail/~ouellet/resp.txt">
Your name: <input type="text" name="yourname"/><br/>
Your quest: <input type="text" name="quest"/><br/>
Your favorite color: <input type="text" name="color"/><br/>
<input type="submit" value="Send e-mail"/>
</form>

The post method must begin with "http://www.library.yale.edu/cgi-bin/cgiemail/" the remainder of the line is the location of the text file you created in step one.
The values given to the NAME properties must be identical to the values used in the brackets [ ] on your E-mail template.

Back to top   View an example


Step 3 (OPTIONAL) : Adding additional text to your success page or creating an alternate success page.

By default the page the user sees after submitting their response is a list of the values they typed into the fields on the form. You can add additional text to the success page by adding the following line to the bottom of your WWW form replacing "Thank you!" with the text you would like added.

<input type="hidden" name="addendum" value="Thank you!"/>

Alternate success page

If you don't like the default page that comes up when email is successfully sent, you can specify an alternate URL using a hidden variable called ''success'' in your HTML form, e.g. <input type="hidden" name="success" value="altsuccess.html">

The HTML document created as the alternate sucess page could be given any name.
The alternate success page must reside in the same directory as the HTML form and value of the "success" tag must only contain the file name, not the whole URL.

The success page should be created in a standard HTML format with the exception being the information you want to carry over from the WWW form. If you want to display information that the user entered in your alternate success page enclose the name values from the WWW form in brackets [ ] Use an alternate success page if you request confidential information from a user.

Note: If you use an editor, such as Dreamweaver, to create your alternate success page be sure that the brackets are written as [ ] and not &#91; and &#93;.

Back to top   View an example


Advanced Options

Required fields

You can require the user to fill in certain fields by preceding the name value with required- . This change must be made on every page that utilizes that field (i.e. WWWform, email template and the alternate success page.

Alternate failure Page

If you use a required field in your form you must also use the alternate failure page. This option uses a hidden varible called "failure". To initiate this option add the following line to your WWWform just below the alternate success URL <input type="hidden" name="failure" value="altfailure.html">

The HTML document created as the alternate sucess page could be given any name.
The alternate failure page must reside in the same directory as the HTML form and value of the "failure" tag must only contain the file name, not the whole URL.

Below are special varibles that should be used when creating a alternate failure page:

Insert [cgirelease] where you want the release number (e.g. 1.4) inserted. Always use this in alternate failure templates.

Insert [cgierrmsg] where you want the error message inserted. Always use this in custom alternate templates.

Insert [cgierrinfo] where you want additional error information inserted. Always use this in alternate failure templates.

Note: If you use an editor, such as Dreamweaver, to create your alternate failure page be sure that the brackets are written as [ ] and not &#91; and &#93;.

Back to top