|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
JavaScript - Form sends email for every page load
Hi, I built a form to send customer info and used some ASP I found on the internet so I'm quite new to it. I got it to send the info I want but I recieve an e-mail every time I navigate away from the page not using the submit button. Here's the ASP I'm using to do it with:
Code:
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Dim title, firstname, surname, email, confirmemail, reason, other, enquiry
title = Request.Form("title")
firstname = Request.Form("firstname")
surname = Request.Form("surname")
email = Request.Form("email")
confirmemail = Request.Form("confirmemail")
reason = Request.Form("reason")
other = Request.Form("other")
enquiry = Request.Form("enquiry")
' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.somesite.co.uk"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "me@somesite.co.uk"
.Item(cdoSendPassword) = "password"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = "someone@something.com"
.From = "someone@something.co.uk"
.Subject = "Customer Enquiry"
.TextBody = "SMTP Relay Test Sent @ " & Now() & vbCrLf & "title: " & title & vbCrLf & "firstname: " & firstname & vbCrLf & "surname: " & surname & vbCrLf & "email: " & email & vbCrLf & "confirmemail: " & confirmemail & vbCrLf & "reason: " & reason & vbCrLf & "other: " & other & vbCrLf & "enquiry: " & enquiry
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>
Does anyone have any ideas? Cheers. |
|
#2
|
||||
|
||||
|
Quote:
Code:
<%
If Request.Form Then
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Dim title, firstname, surname, email, confirmemail, reason, other, enquiry
title = Request.Form("title")
firstname = Request.Form("firstname")
surname = Request.Form("surname")
email = Request.Form("email")
confirmemail = Request.Form("confirmemail")
reason = Request.Form("reason")
other = Request.Form("other")
enquiry = Request.Form("enquiry")
' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp.somesite.co.uk"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "me@somesite.co.uk"
.Item(cdoSendPassword) = "password"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = "someone@something.com"
.From = "someone@something.co.uk"
.Subject = "Customer Enquiry"
.TextBody = "SMTP Relay Test Sent @ " & Now() & vbCrLf & "title: " & title & vbCrLf & "firstname: " & firstname & vbCrLf & "surname: " & surname & vbCrLf & "email: " & email & vbCrLf & "confirmemail: " & confirmemail & vbCrLf & "reason: " & reason & vbCrLf & "other: " & other & vbCrLf & "enquiry: " & enquiry
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
End If
%>
__________________
Scripting problems? Windows questions? Ask the Windows Guru! Stay up to date with all of my latest content. Follow me on Twitter! Help us help you! Post your exact error message with these easy tips! |
|
#3
|
|||
|
|||
|
Thanks for your reply. I tried what you suggested but now I get:
Microsoft VBScript runtime error '800a000d' Type mismatch: '[string: "title=Mr&surname2=th"]' This happens after submit. I'm quite new to this so don't really understand the syntax of javascript but do I need to define the form or something? I'm also using a simple redirect Code:
<%
If Request.form("antispam")= "password" Then
Session("accessok")=true
Response.redirect "thanks.asp"
Else
If Request.form("antispam")<> "" Then
Session("accessok")=false
Response.Write("You didn't get the word right - please try again.")
End if
End If
%>
Doubles up as a basic antispam measure to. Could this be interfering with it? Thanks Last edited by Nukedfood : June 21st, 2009 at 09:33 AM. Reason: More info |
|
#4
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
Quote:
Sorry, I'm forever getting them mixed up. I didn't include the line number because it wouldn't make any sense to anyone who couldn't see the actual line numbers for the code. Shouldve included it. The line is the first one: If Request.Form Then Thanks. |
|
#6
|
||||
|
||||
|
Try using this instead...
If Request.Form.Count > 0 Then |
|
#7
|
||||
|
||||
|
Ignore my last post...it probably works but it's not the proper way to do that. The Form collection returns a query string value when accessed directly. Just check for an empty string.
If Request.Form <> "" Then |
|
#8
|
|||
|
|||
|
Quote:
Thats the ticket, thanks a million! |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > JavaScript - Form sends email for every page load |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|