ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 21st, 2009, 07:30 AM
Nukedfood Nukedfood is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 4 Nukedfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 54 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old June 21st, 2009, 09:19 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,877 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 8 h 39 m 25 sec
Reputation Power: 967
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Quote:
Originally Posted by Nukedfood
Does anyone have any ideas?

Cheers.
You're code is executing every time the page loads because the mail portion is in the global namespace. If you only want to execute when a form is submitted, you need to wrap it in an IF block for that condition.
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
%>
__________________
Don't like me? Click it.

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!

Reply With Quote
  #3  
Old June 21st, 2009, 09:29 AM
Nukedfood Nukedfood is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 4 Nukedfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 54 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old June 21st, 2009, 09:50 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,877 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 8 h 39 m 25 sec
Reputation Power: 967
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Quote:
Originally Posted by Nukedfood
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
Well, first off, this isn't JavaScript. Second, I need you to post the line that is causing the error. It should give you a line number.

Reply With Quote
  #5  
Old June 21st, 2009, 10:14 AM
Nukedfood Nukedfood is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 4 Nukedfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by Nilpo
Well, first off, this isn't JavaScript. Second, I need you to post the line that is causing the error. It should give you a line number.


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.

Reply With Quote
  #6  
Old June 21st, 2009, 10:49 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,877 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 8 h 39 m 25 sec
Reputation Power: 967
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Try using this instead...


If Request.Form.Count > 0 Then

Reply With Quote
  #7  
Old June 21st, 2009, 10:53 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,877 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 8 h 39 m 25 sec
Reputation Power: 967
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
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

Reply With Quote
  #8  
Old June 21st, 2009, 10:59 AM
Nukedfood Nukedfood is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 4 Nukedfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by Nilpo
Try using this instead...


If Request.Form.Count > 0 Then


Thats the ticket, thanks a million!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > JavaScript - Form sends email for every page load


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT