mailform.asp - NIU - Division of Information Technology

      

   

Web & Application Development

mailform.asp

mailform.asp is a general-purpose utility to e-mail the results of a form to a specified "niu.edu" e-mail address. 

  1. Create your form and include the following 'action' in your form tag:
    <form action="http://www.its.niu.edu/its/scripts/mailform.asp" method="POST">
  2. Include the hidden field "mf_to" which specifies the e-mail address to which the results of the form will be mailed:
    <Input type=hidden name="mf_to" value="your_email@niu.edu">

That's it!  All fields in your form will be e-mailed to the address you specify.

More features:

  • Make any field on your form a required field.
  • Include environment variables (such as IP address or browser type) from the client
  • Set your e-mail's 'subject' and 'from' fields
  • Specify redirects to 'success' or 'missing fields' pages

Tip: Each field value in your e-mail will be prefixed with the NAME you assigned it in the field in the form.  Therefore you will want to use explanatory, non-cryptic names for your form fields.  For example, your e-mail will be easier to read if you use something like:
<input TYPE="text" NAME="Favorite_Style_Of_Music ">
rather than: <input TYPE="text" NAME="fav_music"> 
Note: Do NOT use spaces in the names of your fields!

Definitions for Fields:

Field: mf_to  (This is the only required field.  All others are optional)
Description: Specifies the address the form results are mailed to. 
The address(es) must have an "niu.edu" domain.  Any other address(es) are not allowed.
Example: <Input type=hidden name="mf_to" value="your_email@niu.edu">

You can send the form results to multiple addresses by separating them with a semi-colon.  Please note that
- a valid mf_from field must be specified and
- no spaces are allowed between e-mail addresses.
Example: <Input type=hidden name="mf_to" value="address1@niu.edu;address2@niu.edu">


Field : mf_from
Description: E-mail address to appear in the 'from' field. This must be a valid NIU e-mail address.  Make sure this field is hidden.  If you allow users to enter text into this field and they enter a non NIU e-mail address then, for security purposes and to help ensure delivery of the e-mail, the value of this field will be displayed in the e-mail but will not appear in the 'from' field of the e-mail. 
Example: <input type=hidden name="mf_from" value="your_email@niu.edu">


Field: mf_subject
Description: If you want to allow a user to specify the subject, use this parameter as an editable form field. This will be put into the Subject: field of the message you receive. You can set a fixed subject by making this a hidden field.  If not specified, the subject will default to 'WWW Form Results".
Example: <input type=text name="mf_subject">  or  <input type=hidden name="mf_subject" value="Fixed subject">


Field: mf_prevent_html
Description: If you want to allow a user to submit information only in plain text (no html tags allowed), use this parameter as a hidden form field.   If not specified, the user can submit information in html format .
Example: <input type=hidden name="mf_prevent_html" value="Yes" > 


Field: mf_success_redirect
Description: This field specifies the URL where the user will be taken after sucessful form processing and emailing.  If this field is not specified, a default 'success' page which shows all form fields entered by the user will be shown to the user.  Only one of 'mf_success_redirect' or 'mf_success_continue' should be specified.
Example: <input type=hidden name="mf_success_redirect" value="http://your.host.com/to/file.html">


Field: mf_success_continue
Description: This field specifies the URL for a 'continue' link which will be displayed on the default 'success' page along with all form fields entered by the user (see mf_success_redirect).  If this field is not specified, the default 'success' page will be displayed with no links.  Only one of 'mf_success_redirect' or 'mf_success_continue' should be specified.
Example: <input type=hidden name="mf_success_continue" value="http://your.host.com/to/file.html">


Field: mf_results_message
Description: This field specifies additional text to be displayed on the default 'success' page. 
Example: <input type=hidden name="mf_results_message" value="These is some follow-up text for the person who submitted the form.">


Field: mf_required
Description: This field specifies a list of required fields that must be filled by the user before the email is sent. Separate field names with commas.
Example: <input type=hidden name="mf_required" value="email,phone">


Field: mf_missing_fields_redirect
Description: This field specifies the URL where the user will be taken if any required fields have not been filled.  If this field is not specified, a default page which shows the missing fields will be shown to the user.
Example: <input type=hidden name="mf_missing_fields_redirect" value="http://your.host.com/error.html">


Field: mf_env_report
Description: This field specifies any any environment variables you wish to have included in the e-mail.  You can use this field to gather information from the user such as browser type, sender's IP address etc. Here are a few examples:
REMOTE_HOST - The hostname making the request.
REMOTE_ADDR - The IP address of the remote host making the request.
HTTP_USER_AGENT - The type of browser the user has.
Example: <input type=hidden name="mf_env_report" value="REMOTE_HOST,HTTP_USER_AGENT">


Field: mf_email_results
Description: This field specifies whether the values input by users in the form should be emailed as a part of the email body to the address you specified in mf_to. If this field contains "Yes", the form input values are emailed in the body of the email. If this contains "No", the form input values are not emailed in the body of the email. If this field is omitted altogether, it defaults to "Yes", which means that the form input values will be emailed as a part of the email body to the address you specified in mf_to.

Example: <input type=hidden name="mf_email_results" value="No">


Field: mf_attach_results
Description: This field specifies whether the values input by users in the form should be emailed to the address you specified in mf_to as a text file attachment. Use this field if you want to import the form input values into a database or a worksheet. If this field contains "Yes", the form input values are emailed in a text file attachment. If this contains "No", the form input values are not emailed in a text file attachment. If this field is omitted altogether, it defaults to "No", which means that the form input values will not be emailed in a text file attachment. 

Example: <input type=hidden name="mf_attach_results" value="Yes">

Note that the attached text file will be tab delimited.

Here is how you can load the form input values from the attached text file to a Microsoft Excel worksheet or a Microsoft Access table:

FOR MICROSOFT EXCEL:

If you want to open the form input values in a new worksheet:
1. Go to File->Open;
2. In 'Open' dialog box, select "Text Files" as Files of type;
3. Browse to select the attached text file and open it.

If you want to add the form input values in an existing worksheet:
1. Open the worksheet that you want to add form input values to;
2. Go to Data->Get External Data->Import Text File;
3. Browse the attached text file and open it.

FOR MICROSOFT ACCESS:

If you want to open the form input values in a new table:
1. Open the database;
2. Go to Insert->Table->Import Table;
3. In 'Open' dialog box, select "Text Files" as Files of type;
4. Browse to select the attached text file and open it.

If you want to add the form input values as a new row in an existing table:
1. Open the database and the table you want to add the form input values to;
2. Go to File->Get External Data->Import;
3. In 'Open' dialog box, select "Text Files" as Files of type;
4. Browse to select the attached text file and open it.

Notes:

1. If you are using mf_attach_results = "Yes" in your form and your form contains one or more <textarea> fields, you might want to warn the form users not to input an enter character in the <textarea> field. If the 'enter' is hit inside the <textarea> field, you will have difficulty loading the form input data into your worksheet or table.

2. The attached text file contains two lines. The first line will have the field names from the form and the second line will have their respective values that the user entered. If you are trying to load the form input values into an existing worksheet or table, you might be interested in loading the second line only. In such a case, both MS Excel and MS Access allow you to ignore the first one (or many) line in the import process.  

Minor change in Mailform.asp (2/3/2006):

A minor change has been made to Mailform.asp that may affect the users who use its "mf_attach_results" parameter: The file name of the email attachment that contains the form results will no longer contain ".tmp". Example:
Name of the attached file previously: formResults_radB5158.tmp.txt
Name of the attached file now: formResults_radB5158.txt

This change was made to address the problem some users experienced due to the file name while importing the email attachment into MS Access. This change will not affect the users who do not use the "mf_attach_results" parameter.


Example forms:

form utilizing most of the mailform.asp features   

basic feedback form utilizing mailform.asp features