Thursday, August 23, 2007

Simple ASP contact form processor

If you have a contact form like this:

First Name

Last Name

Address

City

State

ZIP Code

Age

Your Question Is?

Email Address

Phone Number



you could use a simple ASP script this to send the submissions via email:
<%
dim emailFrom, emailTo, emailSubject, emailBody
dim objMail, iConf
emailFrom = Request.Form("emailAddress")
emailTo = "hross@jmsonline.com"
emailSubject = "JMS Website: Contact Form Submission"
emailBody = "The following information was submitted from the JMS online contact form:" & vbcrlf &vbcrlf
emailBody = emailBody & "First Name: " & (Request.Form("firstName")) &vbcrlf
emailBody = emailBody & "Last Name: " & (Request.Form("lastName")) &vbcrlf
emailBody = emailBody & "Address: " & (Request.Form("address")) &vbcrlf
emailBody = emailBody & "City: " & (Request.Form("city")) &vbcrlf
emailBody = emailBody & "State: " & (Request.Form("state")) &vbcrlf
emailBody = emailBody & "Zip: " & (Request.Form("zip")) &vbcrlf
emailBody = emailBody & "Age: " & (Request.Form("age")) &vbcrlf &vbcrlf
emailBody = emailBody & "Question: " & (Request.Form("question")) &vbcrlf
emailBody = emailBody & "Email Address: " & (Request.Form("emailAddress")) &vbcrlf
emailBody = emailBody & "Phone: " & (Request.Form("p1")) & Request.Form("p2") & Request.Form("p3") &vbcrlf &vbcrlf
emailBody = emailBody & vbcrlf
set objMail = server.CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")
With iConf.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' CdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Application("EmailServer")
.Update
End With
objMail.From = emailFrom
objMail.To = emailTo
objMail.Subject = emailSubject
objMail.TextBody = EmailBody
objMail.send
Set objMail = Nothing
%>

1 comment:

lawtonterri said...

Perfect post. Here’s a tool that lets youbuild all types of web forms with email alerts fast and without coding. Just point and clickhttp://www.caspio.com/online-database/features/web-forms-online.aspx