FAQ: How do I make a form that will email user comments/information to a specific Portland State email address?

Portland State supplies a central script (FormMail.pl) that will email the results of web forms that use it. To use the script, you need to write an HTML form that points to the script.

Following is an example HTML form which will send email to the address "webmaster@pdx.edu" when someone submits the form. You should test and use your own email address in your form.

<form method="post" action="http://web.pdx.edu/cgi-bin/FormMail.pl">
<input type="hidden" name="recipient" value="webmaster@pdx.edu">
<p>Please enter your name:<br>
<input type="text" name="realname"></p>
<p>Please enter your email address:<br>
<input type="text" name="email"></p>
<p>Please enter your comments:<br>
<input type="text" name="comments"></p>
<p><input type="submit"></p>
</form>

Security

In order to ensure the script does not enable users to email anyone other than the intended recipient, you can only use this script from Portland State websites and send to Portland State email addresses. The script will not copy (cc or bcc) anyone other than the intended recipient email address, and the script will not send an confirmation email to the address entered in the form by the user.

Use with Saga

Note that you can not use the Saga content management system to enter <textarea> fields in your HTML form. Using Saga, you can only use <input type="text"> fields.

If you need to use a <textarea> field on a Saga page, please contact the Saga administrators.

When using a form on a Saga content item, always toggle to HTML Source and ensure that the action of the form is a fully-qualified URL with a domain (eg, http://www.pdx.edu/).

Script Configuration

See how the hidden "recipient" input tag in the example above told the script who to send the mail to? This is how almost all of the script's configuration works.

Here's a list of the most common things you can set with hidden form inputs:

env_report

If this is set, the email will contain a list of the user's computer environment variables, including data like the user's IP address (REMOTE_ADDR) and browser version (HTTP_USER_AGENT), which can be useful if the user is commenting that their computer is having trouble viewing your website.

<input type="hidden" name="env_report" value="REMOTE_ADDR, HTTP_USER_AGENT">

print_blank_fields

If this is set then fields that the user left blank will be included in the email. Normally, blank fields are suppressed to save space.

<input type="hidden" name="print_blank_fields" value="1">

recipient

The email address to which the form submission should be sent. If you would like it copied to more than one recipient then you can separate multiple email addresses with commas, for example:

<input type="hidden" name="recipient" value="you@pdx.edu,someoneelse@pdx.edu">

redirect

If this value is present it should be a full web address (URL), and the user will be redirected there after a successful form submission. The following example will redirect the user to the Portland State home page:

<input type="hidden" name="redirect" value="http://www.pdx.edu/">

If you don't specify a redirect URL then instead of redirecting, the script will generate a page telling the user that their submission was successful.

required

This is a list of fields that the user must fill in before they submit the form. If they leave any of these fields blank then they will be sent back to the form to try again. For example:

<input type="hidden" name="required" value="realname,email,comments">

If you make a field named "email" required, the script will ensure that the email address entered by the user is formatted correctly.

sort

This sets the order in which the submitted form inputs will appear in the email and on the success page. It can be the string "alphabetic" for alphabetic order, or the string "order:" followed by a comma separated list of the input names, for example:

<input type="hidden" name="sort" value="order:realname,email,comments">

If "order:" is used you must supply the names of all of the fields that you want to be in the body of the mail message.

subject

The subject line for the email. For example:

<input type="hidden" name="subject" value="My Website Feedback">

As well as all these hidden inputs, there are a couple of non-hidden inputs which get special treatment:

email

If one of the things you're asking the user to fill in is their email address and you name that input "email", the script will use it as the address part of the sender's email address in the email. If you also make a field named "email" required, the script will ensure that the email address entered by the user is formatted correctly.

<input type="text" name="email">

realname

If one of the things you're asking the user to fill in is their full name and you name that input "realname", formmail will use it as the name part of the sender's email address in the email.

<input type="text" name="realname">