PDA

View Full Version : Help with ASP contact form


velkropie
10-24-2009, 03:37 AM
hello, i was wondering if you could help me with my contact form. i need help with an auto reply section and a way to implement a verification code? here is my code:


<%

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim First
Dim Last
Dim Company
Dim Address
Dim Telephone
Dim Mobile
Dim Website

' get posted data into variables
EmailFrom = Trim(Request.Form("EmailFrom"))
EmailTo = "velkropie@gmail.com"
Subject = "WebFrom Submission"
First = Trim(Request.Form("First"))
Last = Trim(Request.Form("Last"))
Company = Trim(Request.Form("Company"))
Address = Trim(Request.Form("Address"))
Telephone = Trim(Request.Form("Telephone"))
Mobile = Trim(Request.Form("Mobile"))
Website = Trim(Request.Form("Website"))

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

' prepare email body text
Dim Body
Body = Body & "First: " & First & VbCrLf
Body = Body & "Last: " & Last & VbCrLf
Body = Body & "Company: " & Company & VbCrLf
Body = Body & "Address: " & Address & VbCrLf
Body = Body & "Telephone: " & Telephone & VbCrLf
Body = Body & "Mobile: " & Mobile & VbCrLf
Body = Body & "Website: " & Website & VbCrLf

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

' redirect to success page
Response.Redirect("hotline.html?" & EmailFrom)
%>

Mike_O
10-24-2009, 11:28 PM
Hey velkropie,

It's not clear to me exactly what you need help with. Is something in your code not working? Otherwise, it looks okay to me. The only thing I would add is an error handler for the Email library. Something like this:

.
.
on error goto ErrorOccurred
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
.
.
mail.Send
goto Success
ErrorOccurred:
Response.Redirect("error.html?" & EmailFrom)
Success:
Response.Redirect("hotline.html?" & EmailFrom)

Or if you switch to JScript, you can do a a try-catch. Again, hope I understood you correctly.

Regards,
Mike

velkropie
10-25-2009, 06:05 AM
Hey velkropie,

It's not clear to me exactly what you need help with. Is something in your code not working? Otherwise, it looks okay to me. The only thing I would add is an error handler for the Email library. Something like this:

.
.
on error goto ErrorOccurred
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
.
.
mail.Send
goto Success
ErrorOccurred:
Response.Redirect("error.html?" & EmailFrom)
Success:
Response.Redirect("hotline.html?" & EmailFrom)

Or if you switch to JScript, you can do a a try-catch. Again, hope I understood you correctly.

Regards,
Mike

Hey Mike Thanks for your response, i mean when the user sends me an email via the form, the user gets an email automatically informing him/her that i have received the email.

Mike_O
10-26-2009, 12:34 AM
Okay, gotcha. Yea, you're pretty much on the right track. When the user fills out the form and clicks "Send", it will post to the new page (for which you provided the server-side code). This page will:

1. Validate the all the form entries (this is something you already do)
2. Handle errors (this is what I wrote in the previous post)
3. Instead of saying "mail.Send", say "If mail.Send then..."

So, if your send is successful, you can just either post to another page that sends the confirmation back to the user, or just use the same mail object to do that prior to deallocating it in the end.

Also, forgot to mention that you should deallocate your mail object by saying "mail = nothing".

Mike