|
|
ASP Form Emailer:
formhandle.asp
This
script provides powerful and flexible web page form handling.
The script
can work with or without a text control file.
No Control
File Mode:
Using FormHandle.asp without the control file causes the script
to iterate though the form names and value pairs and format them
into an email. In this mode, the script must get all its information
from the calling web page. Normally, some of the required values
are in hidden form fields, but this is not a requirement. The following
field names must be present on your form and should be treated as
reserved words when using this script. The fields marked with *
are required.
Fields:
bcc
- email address for BCC field
bccname - friendly name for BCC field
cc - email address for CC field
ccname - friendly name for CC field
*email - email address for the
FROM field
*emailname - friendly FROM address
- not used in control file mode
error - url of web page to display error message
html - Provides
HTML support in your email (must be set to true)
mailtemplate - name of control file (see below)
priority -
either 1,3, or 5 meaning high, normal, or low priority respectively
subject - subject of the email
success - url of web page to redirect after a successful
email delivery
*to - email address for the
TO field
*toname - friendly name for
the TO field - not used in control file mode
urgent - if set to 1, then message is marked urgent
Typically, it
is recommended that the "to" and "toname" fields
be a hidden value with the address where you desire the email to
be sent. Consideration should be given to hiding the "email"
and "emailname" fields as well, since these fields form
the "From" addresses on your email. Some forms include
a form field where the user can enter their email address and you
might use this field as the return address of the email generated
by formhandle. The problem with this is that many users fail to
enter their email address correctly, or leave it blank in fear of
possible inclusion on email lists. If the email address is incorrect,
or blank, the email generated by this script will fail, resulting
in the non-delivery of the entire form. For this reason, it is suggested
that you use your own email address for the "email" and
"emailname" fields, thus ensuring proper delivery of the
form. If you wish to capture the user's email address on the form,
include a field named "useremail" or some equivalent.
Control File
Mode:
In this mode, Formhandle.asp will read a control file specified
by the hidden form field "mailtemplate" and behave according
to the contents of that file. (The control file is just a text
document that is created and placed in a directory on your web site).
The hidden variable "mailtemplate" specifies the name
of the control file with respect to the web root. If you place the
control file in the root directory, then you can just specify the
filename alone. IMPORTANT:
If you place the control file in a directory below your root directory,
then you must specify the path as well as the filename, for example,
/controlfile/mailtemplate.txt would be the correct value
if the control file were in a directory off the web root called
"controlfile".
Fields/syntax:
::<formhandle_field_name>{,<value>{,<value>}} < text>{[<form_field_name>]}<text>
**values
in {} are optional
::bcc,<emailaddress>,{<easyname>}
- email address for BCC field
::cc,<emailaddress>,{<easyname>} - email
address for CC field
*::email,<emailaddress>,{<easyname>} -
email address for the FROM field
::error,<FullURL> - url of web page to
display error message
::html,<true|false>
- Provides
HTML support in your email (must be set to true)
mailtemplate - name of control file (see below)
::priority,<1,3,5> -
either
1,3,
or 5 meaning high, normal, or low priority respectively
::subject,<subject_text> - subject of the email
::success,<FullURL> - url of web page to redirect after a successful
email delivery
*::to,<emailaddress>,{<easyname>} -
email address for the TO field
::removeblanks,<true|false>,{<replace_value>} -
To not display [YourFieldName] in the email results. Optional:
Will replace the blank field with what you put in the <replace_value>
portion.
::urgent,1 - if set to 1, then message is marked
urgent
Once invoked,
the Formhandle.asp script will begin reading and parsing the
control
file. Each <value> is replaced by the same-named values from
the calling web page. The <formhandle_field_name> values are
replaced by the corresponding values from the reserved-word list
above, while the <form_field_name> valuse are replaced by
the corresponding values from your form. Using this arrangement,
it is possible to construct highly complex email processing scenarios.
Note that the
"toname" and "emailname" variables are ignored
in control file mode. You must specify these values on the "to"
and "email" variable field lines in the following manner:
::to,<email_address>,<friendly_name>
::email,<email_address>,<friendly_name>
Example:
::to,test@test.com,Mr.
Test Email
::email,test@test.com,Mr. Test Return Email
By
using the following example, you should be able to adapt your forms
for use with this script:
Web Page:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>New Page </title>
</head>
<body>
<form method="POST" action="/scripts/formhandle.asp">
<input type="hidden" name="mailtemplate"
value="mailtemplate.txt">
<input type="hidden" name="email" value="user@domain.com">
<input type="hidden" name="emailname" value="thak
t. thak">
<input type="hidden" name="urgent" size="1"
value="1">
<input type="hidden" name="to" value="user@domain.com">
<input type="hidden" name="toname" value="John
Doe ">
<p>email: <input type="text" name="useremail"
size="20"></p>
<p>name: <input type="text" name="name"
size="20"></p>
<p>address <input type="text" name="address"></p>
<p><input type="submit" value="Submit"
name="B1"><input type="reset" value="Reset"
name="B2"></p>
</form>
</body>
</html>
Control File
Sample (text only):
::to,user@otherdomain.com,John Doe
::email,sender@sendingdomain.com,John Doe Sender
Hi. My address is [address] and my name is [name].
Please send info via email to [useremail].
Thanks.
Resulting
Email (text only):
Hi. My address is test and my name is test.
Please send info via email to user@otherdomain.com.
Thanks.
Control File
Sample (HTML):
::to,user@otherdomain.com,John Doe
::email,sender@sendingdomain.com,John Doe Sender
::html,true (If this is not in the control file, the message
will be sent as plain text.)
<HTML><BODY>Hi. My address is [address] and my name
is [name].
Please send info via email to [useremail]. Please visit my website
<a herf="http://www.lonetree.com">Lonetree.com</a>
Thanks.</BODY></HTML>
Resulting
Email (HTML):
Hi. My address is test and my name is test.
Please send info via email to user@otherdomain.com. Please
visit my website Lonetree.com
Thanks.
Discussion:
When Formhandle.asp reads the control file, it takes the value of
the "to" field from the control file - see the first line
- and overrides the value that was specified on the web page. The
script then makes the substitutions for [address], [name], and [useremail]
and the email is sent as formatted above.
Another example...
Control File:
::to,listserv@domain.com,listserv
::email,sender@sendingdomain.com,John Doe Sender
subscribe announcement [useremail]
Resulting Email:
subscribe announcement user@domain.com
Discussion:
In this example, we use the control file to process the form to
subscribe users to a list server. The resulting email is sent to
the listserv address with the subscribe command to subscribe to
the "announcement" list.
Company and product
names are registered trademarks of individual companies and are
respectfully acknowledged.
|