ASP
FormMail
This
script takes generic form
data and sends it as an email. It was written and maintained by Mike
Hall at BrainJar.com and is modeled
after the widely used FormMail script available at
Matt's
Script Archive but is
written in ASP instead of Perl.
Please contact Bee.Net Support staff to have form to email
processing setup for your web site. You can reach us at
support@bee.net or by phone during normal
business hours.
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". Your form ACTION should be set exactly as shown below in the example.
<form action="/mailscripts/formmail.asp" method="post"> <p>
<input name="_recipients" type="hidden" value="support@example.net" />
<input name="_replyTo" type="hidden" value="guest@example.org" /> *see also _replyToField
<input name="_redirect" type="hidden" value="http://www.example.net/thanks.html" />
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" /> </p> </form>
This script
uses specially named form fields as parameters
for controlling the processing. These can be added to the form as
hidden
fields.
Control 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 |
| Field Name |
Description |
_recipients |
Required
The email address to send the form to. Multiple recipients
can be specified by separating addresses with commas (',').
<input name="_recipients" type="hidden" value="admin@example.net" />
or
<input name="_recipients" type="hidden" value="sales@invalid.com,orders@invalid.com" />
|
_replyTo |
An
email address that will be used in the Reply-To
header of the email.
<input name="_replyTo" type="hidden" value="guest@example.org" />
|
_replyToField |
Like _replyTo
except that you specify the name of another field on the form.
Generally, you'd use the name of a field that asks for the user's email
address. Then, the email would have a Reply-To
header set to that address making replies easy.
<input name="_replyToField" type="hidden" value="Email Address" /> ... Your email address: <input name="Email Address" type="text" size="40" />
|
_subject |
Specifies the text to use in the email subject line.
<input name="_subject" type="hidden" value="Site Feedback" />
|
_requiredFields |
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" />
|
_fieldOrder |
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" />
|
_envars |
A
comma-deliminated list of environment variable names. These can be any
of the fields available in the Request.ServerVariables
collection.
<input name="_envars" type="hidden" value="HTTP_REFERER,HTTP_USER_AGENT,REMOTE_ADDR" />
|
_redirect |
Normally when the form has been submitted and the email sent without
any errors the script will display a thank you message along with the
form data. You can change this by specifying the FULL URL of another page in
this field and the user will be sent there instead.
<input name="_redirect" type="hidden" value="http://www.example.net/thanks.html" />
|
Setting Up the Script
Bee.Net
support staff will setup the script for you on request. Just send an
email to support@bee.net or call us during regular business hours. The
script has been customized to work in our hosting environment and there
really is nothing in the script you will ever need to change except for
the fromAddr parameter.
This script will be located in the 'mailscripts' sub-directory under
the 'private' directory of your web site.
Script Parameters
Here is a view of the code with
some example values. The parameters are
described in detail below.
referers = Array("www.example.net","example.net") mailComp = "JMail" smtpServer = "mail.example.net" fromAddr = "guest@example.net"
| FormMail Configuration
Variables |
| Variable Name |
Description |
referers |
This
field is pre-configured by Bee.Net support staff. DO NOT EDIT |
mailComp |
Bee.Net
uses the JMail component. DO NOT EDIT |
smtpServer |
This
field is pre-configured by Bee.Net support staff. DO NOT EDIT |
fromAddr |
This email address will be used as the sender address for the email
created by the script.
Most web hosts do not allow email to be sent from their systems without
a valid From
address in order to discourage spamming. In any case, you should always
use a valid email address for your own site. |
The referers
list is meant simply for your protection. The
script checks the URL of the incoming form against the
values set in
this variable and rejects any that don't match.
Otherwise, anyone from anywhere
could set up a form on their own site, point
it to your script and start sending email from your host without your
consent.
Email Components
The remaining configuration
variables relate to the component used to send
email. Bee.Net uses the JMail component for this script.
|