ASP FormMailView the source code for this ASP script.
[Updated Feb. 28, 2008.]
This script takes generic form data and sends it as an email. It is modeled after the widely used FormMail script available at Matt's Script Archive but is written in ASP instead of Perl.
Note that it is not a direct port of Matt's script. While it has similar functionality it does not attempt to emulate every feature of that script.
It has support for four of the most widely used email components available and can be easily modified to support others. The email produced uses simple HTML formatting which most email clients can support.
Here's a sample, enter your own email address to receive the results.
Keep in mind that this script will require some customization in order to work on any particular site. You may also wish to alter it to suit your needs better, such as by reformatting the output or adding new options.
Setting Up the Form
Just about any new or existing form can use the script by setting its ACTION attribute to the URL where the script resides and making sure its METHOD is set to "POST".
<form action="/scripts/formmail.asp" method="post"> <div> <input name="_recipients" type="hidden" value="email@example.com" /> <input name="_requiredFields" type="hidden" value="Name,Customer ID,Email,Comments" /> Name: <input name="Name" type="text" /><br /> Customer ID: <input name="Customer ID" type="text" /><br /> Email Address: <input name="Email" type="text" /><br /> Comments:<br /> <textarea name="Comments" rows=5 cols=50></textarea> <input type="submit" value="Submit" /> <input type="reset" value="Clear" /> </div> </form>
Like Matt's version, this one uses specially named form fields as parameters for controlling the processing. These can be added to the form as hidden fields.
Below is a listing of these fields. Note that all begin with an underscore ('_') character to distinguish them from any other form fields. Any field name that begins with an underscore is not displayed in the resulting email.
|FormMail Control Fields|
The email address to send the form to. Multiple recipients
can be specified by separating addresses with commas (',').
<input name="_recipients" type="hidden" value="firstname.lastname@example.org" />or
<input name="_recipients" type="hidden" value="email@example.com,firstname.lastname@example.org" />
||Specifies the text to use in the email subject line.
<input name="_subject" type="hidden" value="Site Feedback" />
||A comma-deliminated list of field names that should be
checked for a value. Any missing values causes an error message to be
displayed and the form will not be submitted.
<input name="_requiredFields" type="hidden" value="Name,Address,City,State,Zip,Email" />
||A comma-deliminated list of field names. When building
the email, the fields and values will be displayed in the order specified
here. Note that if you use this option, you must specify the names for all
form fields you want sent.
<input name="_fieldOrder" type="hidden" value="Name,Email,Phone,Address,City,State,Zip" />
||If your form includes a field for the user's email
address, you can specify the name of that field here. The address entered
by the user in that field will be used on the
<input name="_replyToField" type="hidden" value="Email Address" /> ... Your email address: <input name="Email Address" type="text" size="40" />
||Works the same as
<input name="_ccToField" type="hidden" value="Email Address" /> ... Your email address: <input name="Email Address" type="text" size="40" />
||A comma-deliminated list of environment variable names.
These can be any of the fields available in the
<input name="_envars" type="hidden" value="HTTP_REFERER,HTTP_USER_AGENT,REMOTE_ADDR" />
||When the form has been submitted and the email has been
sent, the script will display a "thank you" page showing the information
included in the email. If you specify a URL in this field, the script will
add a 'Continue' link pointing to that URL.
<input name="_continueUrl" type="hidden" value="myHomePage.html" />
||Specify a URL in this field to redirect the user to a
specific page once the email has been successfully sent, rather than
showing the default "thank you" page.
<input name="_redirectUrl" type="hidden" value="myThankYouPage.html" />
You should note that FILE input types are not supported by the script as ASP has no built-in methods for easily dealing with files uploaded from forms.
Before the script can be used, some customization is needed. Much of this depends on the script's location and host environment. There are also options available to help prevent spamming.