Help Request for an ASP Contact Form
I have been working on a contact form for a client, but I keep running into issues with getting the form to actually e-mail. I know that there is something wrong with the ASP programming, but I am not a programmer and using ASP for this is new to me.
Here is the test page that includes the form
What is currently happening is that it always directs to the error page and then does nothing. I had a previous variation that would show the thank you page if fields had something in them, but then it didn't e-mail.
I want it to check that there is something filled in for the required fields (I realize the e-mail address should also be validated, but that's secondary to getting the form to actually send e-mails).
I understand that ASP can be written using vbscript or JavaScript (below is vbscript, I think). I'm not sure it makes a difference for this site, but I'm open to switching to JavaScript syntax for this.
Normally I would use PHP, but this site has always been in ASP and it would take a while to switch to PHP. It's likely in my client's best interest to not make big changes just for one form, and I'm not sure they would play well together if I tried to process the form with PHP.
I have been looking at various tutorials, but I'm not figuring out what the problem is on my own. The tutorials I've found don't all use the same method, so that hasn't really been helping me understand exactly what's causing the issue either. There were some tutorials I found that mentioned specifying the SMTP server, but it seems like there should be a way for it to work without that.
Any help is appreciated, even if it's another tutorial link. Thanks in advance!
The code for the form:
The code to process the form (mostly pre-generated, with some edits):
Here is the test page that includes the form
What is currently happening is that it always directs to the error page and then does nothing. I had a previous variation that would show the thank you page if fields had something in them, but then it didn't e-mail.
I want it to check that there is something filled in for the required fields (I realize the e-mail address should also be validated, but that's secondary to getting the form to actually send e-mails).
I understand that ASP can be written using vbscript or JavaScript (below is vbscript, I think). I'm not sure it makes a difference for this site, but I'm open to switching to JavaScript syntax for this.
Normally I would use PHP, but this site has always been in ASP and it would take a while to switch to PHP. It's likely in my client's best interest to not make big changes just for one form, and I'm not sure they would play well together if I tried to process the form with PHP.
I have been looking at various tutorials, but I'm not figuring out what the problem is on my own. The tutorials I've found don't all use the same method, so that hasn't really been helping me understand exactly what's causing the issue either. There were some tutorials I found that mentioned specifying the SMTP server, but it seems like there should be a way for it to work without that.
Any help is appreciated, even if it's another tutorial link. Thanks in advance!
The code for the form:
<h1>Contact Form</h1>
<form method="post" action="contactformscript.asp" id="form" name="form">
<p><strong class="formreq">Full Name*:</strong> <input type="text" name="sfullname" size="30"></p>
<p><strong>Company Name:</strong> <input type="text" name="scompanyname" size="28"></p>
<p><strong class="formreq">E-mail*:</strong> <input type="text" name="sFromEmail" size="34"></p>
<p><strong class="formreq">Phone*:</strong> <input type="text" name="sphone" size="14"> <small>(including area code)</small></p>
<p><strong>Preferred Method of Contact:</strong> <input type="radio" name="scontactmethod" value="email"> E-mail <input type="radio" name="scontactmethod" value="phone"> Phone</p>
<div class="spacer10"></div>
<p><strong>Have a question or any comments? Please let us know:</strong></p>
<p><textarea rows="5" cols="40" name=s"scomments"></textarea></p>
<div class="clr"></div><input type="submit" name="Submit" value="Send" class="submitbutton">
<input type="reset" value="Reset" class="resetbutton">
</form>
<form method="post" action="contactformscript.asp" id="form" name="form">
<p><strong class="formreq">Full Name*:</strong> <input type="text" name="sfullname" size="30"></p>
<p><strong>Company Name:</strong> <input type="text" name="scompanyname" size="28"></p>
<p><strong class="formreq">E-mail*:</strong> <input type="text" name="sFromEmail" size="34"></p>
<p><strong class="formreq">Phone*:</strong> <input type="text" name="sphone" size="14"> <small>(including area code)</small></p>
<p><strong>Preferred Method of Contact:</strong> <input type="radio" name="scontactmethod" value="email"> E-mail <input type="radio" name="scontactmethod" value="phone"> Phone</p>
<div class="spacer10"></div>
<p><strong>Have a question or any comments? Please let us know:</strong></p>
<p><textarea rows="5" cols="40" name=s"scomments"></textarea></p>
<div class="clr"></div><input type="submit" name="Submit" value="Send" class="submitbutton">
<input type="reset" value="Reset" class="resetbutton">
</form>
The code to process the form (mostly pre-generated, with some edits):
<%
' Website Contact Form Generator
' http://www.tele-pro.co.uk/scripts/contact_form/
' This script is free to use as long as you
' retain the credit link
' declare variables
Dim EmailTo
Dim Subject
Dim sfullname
Dim scompanyname
Dim sFromEmail
Dim sphone
Dim scontactmethod
Dim scomments
' get posted data into variables
EmailTo = "emily@internationalsafety.com"
Subject = "Contact via the ISS website"
sfullname = Trim(Request.Form("sfullname"))
scompanyname = Trim(Request.Form("scompanyname"))
sFromEmail = Trim(Request.Form("sFromEmail"))
sphone = Trim(Request.Form("sphone"))
scontactmethod = Trim(Request.Form("scontactmethod"))
scomments = Trim(Request.Form("scomments"))
' validation
Dim validationOK
validationOK=true
If (Trim(sfullname)="") Then validationOK=false
If (Trim(sFromEmail)="") Then validationOK=false
If (Trim(sphone)="") Then validationOK=false
If (Trim(scomments)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("error.asp")
' send email
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = EmailTo
objMail.From = sFromEmail
objMail.Subject = Subject
objMail.Body = "Full Name: " & sfullname & VbCrLf & _
"Company Name: " & scompanyname & VbCrL & _
"Email: " & sFromEmail & VbCrL & _
"Phone: " & sphone & VbCrLf & _
"Preferred Method of Contact: " & scontactmethod & VbCrLf & _
"Question(s) or Comment(s): " & scomments
objMail.BodyFormat=0
objMail.MailFormat=0
objMail.Send
Set objMail = nothing
' redirect to success page
Response.Redirect("thankyou.asp")
%>
' Website Contact Form Generator
' http://www.tele-pro.co.uk/scripts/contact_form/
' This script is free to use as long as you
' retain the credit link
' declare variables
Dim EmailTo
Dim Subject
Dim sfullname
Dim scompanyname
Dim sFromEmail
Dim sphone
Dim scontactmethod
Dim scomments
' get posted data into variables
EmailTo = "emily@internationalsafety.com"
Subject = "Contact via the ISS website"
sfullname = Trim(Request.Form("sfullname"))
scompanyname = Trim(Request.Form("scompanyname"))
sFromEmail = Trim(Request.Form("sFromEmail"))
sphone = Trim(Request.Form("sphone"))
scontactmethod = Trim(Request.Form("scontactmethod"))
scomments = Trim(Request.Form("scomments"))
' validation
Dim validationOK
validationOK=true
If (Trim(sfullname)="") Then validationOK=false
If (Trim(sFromEmail)="") Then validationOK=false
If (Trim(sphone)="") Then validationOK=false
If (Trim(scomments)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("error.asp")
' send email
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = EmailTo
objMail.From = sFromEmail
objMail.Subject = Subject
objMail.Body = "Full Name: " & sfullname & VbCrLf & _
"Company Name: " & scompanyname & VbCrL & _
"Email: " & sFromEmail & VbCrL & _
"Phone: " & sphone & VbCrLf & _
"Preferred Method of Contact: " & scontactmethod & VbCrLf & _
"Question(s) or Comment(s): " & scomments
objMail.BodyFormat=0
objMail.MailFormat=0
objMail.Send
Set objMail = nothing
' redirect to success page
Response.Redirect("thankyou.asp")
%>
