Information Technology Services, Bethel College and Seminary
ITS Documents

Bethel > ITS > Resources
Call 651-638-6500 for all computing needs at Bethel
ITS  Link Bethel Link [an error occurred while processing this directive]

FormMail Howto

Table of Contents

Introduction:

What is FormMail, and why should I use it?

Before this script, any Bethel website-author who wanted to have a web page that gathered input and then e-mailed it to the persons interested had to ask the webmaster to create a custom cgi script for that specific form. Over time, this practice created too many forms that were all the same except for a few details. This also created an inconvenience for the website-authors, since they had to submit a request and then wait until the webmaster had time to tend to it.

This FormMail script removes all of that extra overhead, and places the power of form mailing completely in the hands of the website-author. And best of all, no cgi scripting is required!

Copyright Notice: This version of FormMail has been enhanced from the original open source FormMail, which can be found at Matt's Script Archive, to give even more power back to you, the website-author.

New Features

E-mail the form submitter (e-mail confirmation):

Bethel FormMail allows web authors to automatically send confirmation e-mails back to the submitter of the form.

Security Enhancement:: Rate Limiter:

In order to prevent spammers and DOS attackers from using our forms which allow e-mail comfirmations for their own purposes, we have developed a way to limit the number of form access by ip address. You can access FormMail forms on our site a maximum of five times in one hour. If you exceed this limit you are blocked, and can only submit one form per hour. After 24 hours, you will be unblocked.

This feature is only needed for a form that sends an e-mail confirmation back to the form submitter. By default, it is turned off. If you form is not located on the bethelnet, you MUST turn it on if you are going to send confirmation e-mails! You can turn it on by adding the following to your configuration file:

abuselimiter=on

Templates and hidden configuration (bethelnet):

Web designers can now use templates to help format the 'thank you for submitting' (e.g. form results) html page.
The power of FormMail is that it is generic enough to allow many forms to use the same cgi code. Formerly, it was configured by using hidden fields in the html form. This poses a security risk, since those hidden fields can be compromised. To increase security, the configuration has been removed from the html form to special files that aren't accessible from the web. These files are location in /data directories. Here is an example of how this works:

  • The URL of the form is /seminary/sandiego/admform.html.
  • There is a data directory in /seminary/data.
When the form located on admform.html is submitted, formmail looks for a data directory that is closest to (/seminary/sandiego/admform.html). It first checks /seminary/sandiego, and doesn't find one. It then looks in /seminary, and there finds a /data directory. Inside /seminary/data, it looks for these four files:
  • admform.html.fmc #formmail configuration file
  • admform.html.results #html 'thank you' template

The only required file is admform.html.fmc. If the results file is not found, a generic template is used.

      JavaScript variables of form fields

Sometimes you want more flexibility over what is displayed on the 'thank you' page. What if you want to say something different depending on whether the user submitted a 'yes' or a 'no'? Well, now this is all possible. Using templates, you can now include form fields as javascript variables. For more information, check out the template description and the configuration parameter

Configuring Formmail

As described above in the 'New Features' Section, the formmail configuration is now placed in the hidden '/data' directory closest to the actual form location.
Configuration parameters are placed in that file, one per line, in the format of:

parameter=value

Actually, some configuration parameters are located in the form itself, like email. If the parameter is supposed to be specified in the form itself, the example will be in html. Otherwise, the parameter should be placed in the configuration file.

Necessary Configuration Parameters

There is only one necessary parameter, and that is the recipient.

Fieldrecipients
Description: This form field allows you to specify the e-mail recipient(s) of your form results. You can include multiple recipients by separating the values with commas.
Syntax:
recipients=user1@bethel.edu,user2@somewhereelse.com

Optional Configuration Parameters

Fieldrecipient_from
Description: This parameter allows you to specify the return email address of the envelope header. If this is not specified, the first email address in the recipients parameter will be used. NOTE: this needs to be a bethel email address!
Syntax:
recipient_from=user1@bethel.edu
Fieldsubject
Description: The subject field will allow you to specify the subject that you wish to appear in the e-mails that are sent after the form has been filled out. Depending on the e-mail, 'submission' or 'confirmation' will automatically be appended to this. You can also insert the value of a form field into the subject line. Use the pattern: $[fieldname]. The form field is truncated to a length of no more than 30 characters before it is added to the subject. The default if not present in configuration:
    Bethel Form (Submission or Confirmation)
Syntax:
subject=Your Subject
To change the subject to Bethel Admissions Form:
subject=Bethel Admissions Form
subject=CARS Account Request LOGIN: $[LoginName]
Now in the recipient e-mail, the subject will be: 'Bethel Admissions Form Submission', and if there is a confirmation e-maill, the subject will be: 'Bethel Admissions Form Confirmation'. On the second example, if the value of the LoginName input field was 'myusername', the subject would be 'CARS Account Request LOGIN: myusername'.
Fieldemail
Description: This form field will allow the user to specify their return e-mail address. If you want to be able to return e-mail to your user, I strongly suggest that you include this form field and allow them to fill it in. This will be put into the From: field of the message you receive. If you want to require an email address with valid syntax, add this field name to the 'require' parameter.
Syntax:
<input type=text name="email">
Fieldconfirm_email_fields
Description: If this field is set, a copy of the confirmation e-mail will be sent to all valid e-mail addresses in this list. Note: confirmemail must be set in order to use this field!
Syntax:
confirm_email_fields=email1@somewhere.com,email2@someotherplace.net,email3@bethel.edu
Fieldstdtemplate
Description: There are a couple results html templates that are supplied, so you don't need to create your own. There is one template for each major look and feel on the website. Current, there are three of these: Bethel Official (official), Bethel College (college), and Bethel CGCS (cgcs).
Syntax: To use one of these templates, include this parameter in the configuration file, with it's value being 'official','college', or 'cgcs'.
stdtemplate=cgcs
Fieldconfirmemail
Description: If you wish to send a confirmation e-mail to the submitter of the form, place this in that form's configuration file. If confirmheader and confirmfooter are not present in the configuration file, then suitable defaults will be used. The default looks like this:
Bethel College and Seminary online forms submission.

The following is the information that you posted on DATE:

LIST OF FORM RESULTS, ONE FORM FIELD PER LINE
Syntax:
confirmemail=1
Fieldconfirmheader
Description: Use this option to specify the first line or few of the confirmation e-mail. If this is not present in the configuration file, then the default will be used.
Default:
    The following is the information that you posted on DATE
If your form is configured to send a confirmation e-mail (via confirmemail), then you should also use this.
Syntax:
confirmheader="Listed below is what you submitted to us."
Fieldconfirmfooter
Description: Use this option to specify the last line or few of the confirmation e-mail. If this is not present, then there will be no footer.
Using this is suggested if you are sending confirmation e-mails.
Syntax:
confirmfooter="Thank you for your interest in Bethel College and Seminary."
Fieldjsfields
Description: When this parameter is used in conjunction with the jsfields template function, the form fields specified here are converted to javascript variables and inserted into the results html page. In this way, you can develop a template that can display something different depending on what was input into the form. An example of where this could come in handy would be if you wanted to display a different page depending on whether the form submitter selected a 'yes' or 'no'. Check the jsfields template function for an example.
Syntax:
jsfields=answer,email
Fieldnamemap
Description: This is a comma-delimited list of field/name pairs. This allows you to change the name of a field in the results html and e-mails. A good use of this is to provide a better description (which allows spaces, etc) than a field name.
Syntax:
namemap=cname:Contact Name,fname:First Name,lname:Last Name
Field referer
Description: This is a regular expression of sites that are allowed to use this form.
Syntax: To let all bethel sites use this form:
    referer=bethel
To only allow referals from www.bethel.edu:
    referer=www.bethel.edu
To only allow referals from one form:
referer=www.bethel.edu/admissions/admform.htm
Field allowurls
Description: This is a list of fields in the form that allow http or ftp urls to be placed in. By default, no (http://name or ftp://name) text is allowed in any form field, which reduces the appeal to spammers.
Syntax:
allowurls=website,comments
Fieldhidefields
Description: This is a list of fields that aren't presented in the results page and the two e-mails that are sent out. This is most useful for named form fields that don't need to be in the results, like a submit or reset button.
Syntax:
hidefields=submit
Field realname
Description: The realname form field will allow the user to input their real name. This field is useful for identification purposes and will also be put into the From: line of your message header.
Syntax:
<input type=text name="realname">
Field redirect
Description: If you wish to redirect the user to a different URL, you can use this to send them to a pre-made HTML page.Note: if you wish to supply a custom 'Thank you' page, you should use the results template as described in the 'New Features' section
Syntax:
redirect=http://your.host.com/to/file.html
Fieldrequire
Description: You can now require certain fields in your form to be filled in before the user can successfully submit the form. If the required fields are not filled in, the user will be notified of what they need to fill in, and a link back to the form they just submitted will be provided.
Note: To use a customized error page, see missing_fields_redirect.
Syntax: If you want to require that they fill in the email and phone fields in your form, so that you can reach them once you have received the mail, use a syntax like:
require=email,phone,fname
Fieldenv_report
Description: Allows you to have Environment variables included in the e-mail message you receive after a user has filled out your form. Useful if you wish to know what browser they were using, what domain they were coming from or any other attributes associated with environment variables. The following is a short list of valid environment variables that might be useful:
REMOTE_HOST Sends the hostname making the request.
REMOTE_ADDR Sends the IP address of the remote host making the request.
REMOTE_USER If server supports authentication and script is protected, this is the username they 
have authenticated as. (This is not usually set.) HTTP_USER_AGENT The browser the client is using to send the request.
If you are also using the sort_on param, make sure the environment variables you want to include are listed in that param!
Syntax: If you wanted to find the remote host and browser sending the request:
env_report=REMOTE_HOST,HTTP_USER_AGENT
Fieldsort
Description: This field allows you to choose the order in which you wish for your variables to appear in the e-mail that FormMail generates. You can choose to have the field sorted alphabetically or specify an order.
If this is left out, it will default to the order in which the browser has sent form (usually the same order the form.
Syntax: To sort alphabetically:
sort=alphabetic
To sort by a set field order:
sort=order:name1,name2,etc...
Fieldprint_config
Description: print_config allows you to specify which of the config variables you would like to have printed in your e-mail and results messages. By default, no config fields are printed.
Syntax: If you want to print the email and subject fields:
print_config=email,subject
Fieldprint_blank_fields
Description: print_blank_fields allows you to request that all form fields are printed in the e-mail and results messages, regardless of whether or not they were filled in. The default is off.
Syntax:
print_blank_fields=1
Field title
Description: This form field allows you to specify the title and header that will appear on the resulting page if you do not specify a redirect URL. The default title is 'Bethel Thanks You'.
Syntax: If you wanted a title of 'Feedback Form Results':
title=Feedback Form Results
Fieldreturn_link_url
Description: This field allows you to specify a URL that will appear, as return_link_title, on the results page page. This field will not be used if you have the redirect field set. It is useful if you want to allow the client to return to some other page.
Syntax:
return_link_url=http://your.host.com/main.html
Field return_link_title
Description: This is the title that will be used to link the user back to the page you specified with return_link_url.
Syntax:
return_link_title=Back to Main Page
Fieldabuselimiter
Description: If your form is publicly accessible (e.g. not on bethelnet) and it is sending confirmation e-mails, then you need to turn on the abuse limiter. This feature makes our forms less appealing to spammers.
Syntax:
abuselimiter=on


Examples

    Since the separation of configuration and templates from the html form can be confusing, here are some examples that will hopefully increase your understanding. These examples are using the following structure for the file locations:
  • html form location:
    http://www.bethel.edu/admissions/postjob.html
  • form configuration:
    http://www.bethel.edu/admissions/data/postjob.html.fmc
  • form results template:
    http://www.bethel.edu/admissions/data/postjob.html.results
Configuration File
    A configuration file could look as simple as this:
    recipients=Webmaster 
    referer=bethel.edu
    
    This is the most basic configuration you can have. It will send the form to the webmaster, and only allows web pages located in the bethel.edu domain to use it. The html thank you page will use the default 'Bethel Thanks You' html template.

    Here is a sample configuration file for the above form.

    recipients=Webmaster ,Admissions 
    subject=Job Posting Request
    require=employer,contact,phone,email
    referer=bethel.edu
    return_link_url=http://www.bethel.edu/admissions/postjob.html
    return_link_title=Return to the form
    namemap=qualifications:What are your qualifications,employer:Employer,jobcatagory:Job Catagory
    allowurls=website
    hidefields=Submit
    
    The recipients of this form are the webmaster and admissions e-mail addresses. The subject of the e-mails that are send out will be 'Job Posting Request'. There are four fields that are required: employer, contact, phone, and email. Only Bethel pages are allowed to use this form. It is using the default results html and e-mail templates, and on the results html, a link back to the form is provided. In the results html and e-mails, the form field qualififications will be listed as 'qualify', and the field employer will be listed as 'Employer'. Also, a website address is allowed to be placed in the 'website' field, and the field named Submit will not be displayed..

Templates

    How to setup a template file

    The templating options look very much like custom html server side includes. They follow the pattern: <!--%name--> and can be inserted in the results html template, and the recipient and submitter e-mails. Five template functions are supported: jsfields, titlehead, title, formresults, and date.

      Name: jsfields
      Use: Results html page
      Description: This function converts the fields specified in jsfields to javascript variables. In this way, you can develop a template that can display something different depending on what was input into the form. An example of where this could come in handy would be if you wanted to display a different page depending on whether the form submitter selected a 'yes' or 'no'. If jsfields configuration parameter is: jsfields=answer, and on the previous form, answer was two radio buttons, one with a value of 'yes', the other of 'no', then this will be what is inserted in the results html:

      <script language='javascript'><!--var answer='(either yes or no)';//--></script>
      Here is how you could use this in your template:
      <script language='javascript'><!--
      if (answer = 'yes') { document.write("you chose yes<br>");}
      elsif (answer = 'no') { document.write("you chose no<br>");}
      //--></script>
      Name: titlehead
      Use: Results html page
      Description: This function prints html code for the header title of the results html page. This should be placed in the html header. The title is retrieved from the 'title' configuration parameter.

      Name: title
      Use: Results html page
      Description: This function (like titlehead) prints the formatted title to be placed in the body of the results html page. The title is retrieved from the 'title' configuration parameter

      Name: formresults
      Use: Results html page and both the recipient and submitter e-mails
      Description: This function will output the results of the form. If used in the results html page, will return a table containing the results. If used in one of the e-mail templates, will return a tab-delimited list.

      Name: date
      Use: Results help page and both the recipient and submitter e-mails
      Description: This function returns an unformatted date.

    For the html template, you can also use stylesheets to customize the colors/layout of your page. The title on the page uses the class 'royal', and the cell on the left side of the table use the class 'fname', while the the right cells use the class 'value'.

    Html Template

    This is a bit more involved, so you have two choices:


[an error occurred while processing this directive]