ASP Form Mail | ||||||||||||||||||||||
|
FormMail.asp uses control values taken from hidden form fields to set parameters such as the email address to send the data to, the subject text for the email, which fields are required, what order to list the fields, etc. You can try it out on the form below. Required fields are marked with an asterisk ('*'). Leaving them blank results in an error message. When filled out correctly, the submitted form data is emailed to the address you supply below.
You might notice that the form above uses a bit of JavaScript code to copy the value you enter in the 'Email Address' field to the hidden '_recipients' field. Normally you would hard code a value for that field, but here it allows you to send the form data to yourself to see the results. See below for details on the '_recipients' field. Using the Script The script can be used with most forms just by adding a few hidden fields. Also, it can only be run on our NT based servers - if you unsure if your site is on our NT servers, contact us and we will advise. If you are on our Linux servers you must use FormMail.cgi. Regardless, you'll need ask xcelNet to add you to the Referrers - this is facility reserved for xcelNet Clients only. The Post command is: <form method="post" action="http://www.xcelnet.com.au/cgi-bin/FormMail.asp">Form Setup With the script set up on your host, you can set your forms to use it by pointing them to the script and adding some hidden fields to pass control data. The control fields are:
You should note that, except for the above, any field name starting with an underscore ('_') character is ignored. This allows you to customize the script by adding your own control fields. Also, although you can use spaces within a field name, you should avoid using them at the start or end of any name. The script tends to strip leading and trailing spaces when processing field names. Also avoid using commas (',') as these are used to deliminate multiple values in control fields. How it Works The script is really fairly simple, it's the number of options that add to the length of the code. Basically, it follows this outline to check for errors. Anytime an error is found, a message is added to a list.
To help prevent errors in sending the email, all email addresses are checked for proper syntax. Likewise, if an error occurs in sending the email, a message is generated and the resulting page informs the user of the problem. Note that possible errors in sending email will vary depending on the component used and on individual host settings. For example, the default CDONTS component included with IIS never returns an error, it simply acts as though the process succeeded normally. ASPMail and JMail, however, do return an error code along with a descriptive text message. Check the documentation for your specific component and with your host provider to diagnose any problems. Some points of interest in the code are described below. Parsing Multiple Values For control fields that allow multiple values such as _recipients or _requiredFields, the script uses the built in Split() function to create an array of values from a single string. These arrays can then be used in loops to check or process each individual value. Getting the Field Order Also of note, when no specific field order is given, we want to display the fields in the order they arrive at in the form request header. This is usually the order in which the individual form tags appear in the HTML page. All fields and values are taken from the Request.Form collection. So you would think that a simple 'for each' loop like this
for each name in Request.Form
Response.Write(name & ": " & Request.Form(name) & vbCrLf)
next
would display them in that order. However, looping through a collection in ASP
with this method does not necessarily keep the order. But accessing the
collection as an array like this
for i = 1 to Request.Form.Count
Response.Write(Request.Form(i) & vbCrLf)
next
will keep the proper order. The problem is, the field name is lost. The
FormFieldOrder() function fixes that by looping through the collection as
an array, and in an inner loop, uses the 'for each' method to match the name to
the array index.
In the end, it returns an array of field names in the proper order. This array is then used to loop through the form field collection and retrieve the names and values in order. Creating and Sending the Email The email note generated uses HTML tags for formatting to make it look better. Most email clients support this as do the three email components the script is designed to use. It's just a matter of setting an option or two to create the proper email header.
|
||||||||||||||||||||||
|
"Providing Personalised Service and a Network of
Excellence"
|
|
Legal Notices & Privacy Policy © 1996-2003 xcelNet Enterprise, All rights reserved SiteAdmin@xcelnet.com.au |
| To ensure you have the Latest Information, Click Here to Refresh this Page |