Generic Email Form Handler

Do you have a response form that you need emailed to you? The following script grabs the form responses and then packages it all up to send using CDONTS. For the purposes of this script, the only item in the form we're validating is the Comments field (what good is a comments form if there are no comments? LOL). Additional form validation can easily be added if desired; if you use a javascript to validate before the form is submitted, you won't even need to include the validation at all in the email script.

Note: SMTP must be installed on the server for this to work. If you get an error saying the object couldn't be created, its because SMTP isn't installed on the system. In that case, check with the system administrator to see if there's an email component installed on the server or if you can get one installed. One such email component is ASP QMail - see the ASP QMail script for a sample ASP QMail script.

 <%

If request.form("Comments")="" then
    response.write "<p><br><center><font face='arial' size=3>"
    response.write "<b>Please don't forget to enter your"
	response.write " comments or question!</b></font>"
    response.write "<form>"
    response.write "<input type=""button"" value=""Return to Form"""
	response.write " onclick=history.go(-1)></form>"
    response.end
End If
' this is where we package up the information for the body of then
' message using the variable named Message and a For...Next statement
' that grabs each item passed from the form. This example returns all the
' form fields in their proper tab order by using keys. 
' The vbCrLf is a carriage return/line feed; its there to add line breaks
' to the completed email message. 
for i=1 to request.form.count
    Message = Message & request.form.key(i) & ": " & request.form.item(i) & vbCrLf
Next

' now we'll create the mail object and fill in the
' various email fields
Set objMail = CreateObject("CDONTS.Newmail")
objMail.From = request.form("Email")
objMail.To = "kathi@attitude.com"
objMail.Subject = "ASP Site Form Submission"
objMail.Body = Message
objMail.Send
Set objMail = Nothing
' now add confirmation that the mail was sent and/or other
' scripting as desired
%>