PDA

View Full Version : Automatic email response with ASP


jcx1028
09-24-2008, 09:00 PM
I currently have a basic contact form on a website that sends the information to my email address and redirects the user to a Thank You page. What I'd like to add, if possible, is an automatic reply to the individual submitting the form, with the subject line reading something like, "Thank you" and the body reading something like, "A member of our team will be in touch shortly."

Can this be done via the .asp file? Any assistance would be greatly appreciated. Here's what I'm working with so far...

<%
' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim Phone
Dim Email
Dim Comments

' get posted data into variables
EmailFrom = Trim(Request.Form("Email"))
EmailTo = "info@rgnengineering.com"
Subject = "Contact Us"
Name = Trim(Request.Form("Name"))
Phone = Trim(Request.Form("Phone"))
Email = Trim(Request.Form("Email"))
Comments = Trim(Request.Form("Comments"))

' validation
Dim validationOK
validationOK=true
If (Trim(EmailFrom)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "Phone: " & Phone & VbCrLf
Body = Body & "Email: " & Email & VbCrLf
Body = Body & "Comments: " & Comments & VbCrLf

' send email
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = Email
mail.Subject = Subject
mail.Body = Body
mail.Send

' redirect to success page
Response.Redirect("thank-you.html")
%>

Spudhead
09-25-2008, 12:51 PM
Yeah, just send another email like you are doing, with the from and to emails swapped round. You might want to set your objects to nothing when you're done with them, just to be all tidy.

Set mail2 = Server.CreateObject("CDONTS.NewMail")
mail2.To = Email
mail2.From = EmailTo
mail2.Subject = Subject
mail2.Body = Body
mail2.Send
set mail2 = nothing