Skip to page content Home Hosting Development Tools & Services Help Desk

Tools: Email Gateway Programming Guide

Overview

The Email Gateway form handler formats and emails data received from a web form. Common usage includes contact or feedback forms. Note that the often the easiest way to get email from your site visitors is simply to add a mailto link, e.g.

<a href="mailto:yourid@bsd.uchicago.edu">email me<a>.

To create a form that uses this program you do not need to do any programming; however, you do need to set it up according to the guidelines below so your form can communicate with our program.

How to Configure the Web Form

form action
http://tomcat.bsd.uchicago.edu:8080/servlet/junk.MailForm
form method
post
email-to (hidden)
the email address(es) that you want to receive the email - separate multiple addresses with a comma
email-from (hidden)
a valid BSD email address, such as your address
email-subject (hidden)
whatever you want for the email Subject line, e.g. Email from website
email-response-template (hidden)
an absolute URL pointing at an HTML file that the visitor will see after s/he hits submit, e.g. http://yoursite.bsd.uchicago.edu/thanks.html
email-message-template (hidden)
an absolute URL pointing at a plain text file that determines how the user input is formatted in the email , e.g. http://yoursite.bsd.uchicago.edu/email-template.txt -- see below
your form input fields
you can use any field types but take care to set a name attribute and when necessary a value attribute

How to Create the Message Template

The hidden form variable email-message-template points to an absolute URL pointing at a plain text file that determines how the user input is formatted in the email. The message template is merged with form input to create the email content. This allows you to add spacing, labels, etc. The template uses a simple variable substitution: if the program sees any form field names in the template it will replace that name with the actual user data from. The form field names are identified by placing the name inside brackets prefixed with a dollar sign: ${form_field_name}. For example, if your form has two input fields, with the name attributes set to "Name" and "Degree" you can create a message template that looks like this:

Name: ${Name}
Degree: ${Degree}

Save this template as a plain text file (i.e. do not use Word) on your website and set the email-message-template variable in your form. When Professor John Frink submits the form the email you get will looks like this:

Name: John Frink
Degree: Ph.D.

Please note that the template system is case-sensitive and uses the name attribute (not the id) of any form field. You do not have to use all your fields or keep them in the same order as on the form itself.