[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

Syntax Based Error When Submitting Form

I am trying to get a web form to act as an email form but am having some difficulties with syntax.  Server is a windows 2003 server.

The form bascally posts data to a script and then the script takes the Querystring, retrives information from the DB and then gets the email address of the user from the DB and that is the address i need to to post to.

Here is my script:
**********************************************
<!--#include virtual="/includes/connection_string.asp"-->

<!--METADATA TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib"
UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library" -->

<%
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")

'GETS THE PROPERTY ID FROM THE QUERYSTRING SET BY THE FORM
PropertyID = Clng(Request.QueryString("ID"))

'SETS THE RECORDSET TO BE THE RECORD FROM THE TABLE PROPERTIES WHERE IS EQUALS THE QUERYSTRING
Set RS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM tblProperty WHERE ID=" & PropertyID
RS.Open SQL, Connection

'USING LAST RECORDSET IS SET THE USERID VARIABLE TO BE THE INTUSERID (PROPERTY OWNER) WHICH WILL
'THEN BE MATCHED AGAINST THE USERS TABLE TO GET THE EMAIL ADDRESS
UserID = RS("intUserID")

'CLOSES RECORDSET SO THAT WE CAN REOPEN IT ON THE USERS TABLE
RS.Close
Set RS = Nothing

'CREATES A NEW RECORDSET
Set RS = Server.CreateObject("ADODB.Recordset")

'SELECTS THE RECORD FROM THE USERS TABLE FOR THE OWNER OF THE PROPERTY SET IN THE USERID VARIABLE
SQL1 = "SELECT * FROM tblUsers WHERE ID=" & UserID
RS.Open SQL1, Connection

EmailAddress = RS("txtEmailAddress")

'Configuration:
objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort

objConfig.Fields(cdoSMTPServer)="**SMTP SERVER HERE**"
objConfig.Fields(cdoSMTPServerPort)=25
objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
objConfig.Fields(cdoSendUserName) = "**MY EMAIL BOX HERE**"
objConfig.Fields(cdoSendPassword) = "**MY EMAIL PASSWORD HERE**"

'Update configuration
objConfig.Fields.Update
Set objMail.Configuration = objConfig

objMail.From = Request.Form("EmailAddress")
objMail.To = EmailAddress
objMail.Subject = "Website Enquiry From: " & Request.Form("Name")
objMail.TextBody = Request.Form("Email")

objMail.Send

If Err.Number = 0 Then
  Response.Redirect "/contact_us.asp?ID=" & Response.Write(PropertyID)
Else
  Response.Write("Error sending mail. Code: " & Err.Number)
  Err.Clear
End If

RS.Close
Set RS = Nothing
Connection.Close
Set Connection = Nothing
Set objMail=Nothing
Set objConfig=Nothing
%>
***********************************************************

It fails on the objMail.Send line with the error:

***********************************************************
error '8004020e'
/processing/process_send_contact_us.asp, line 58
***********************************************************

Im assuming the problem is with the line:
**********************************
objMail.To = EmailAddress
**********************************

i have tried the objMail.To = RS("txtEmailAddress")
i have tried the objMail.To = response.write (RS("txtEmailAddress"))

both to no avail.

can someone see if they can find the problem?  i think it is only a simple one that is syntax based!

Thanks,
Carl

0
net-workx
Asked:
net-workx
3 Solutions
 
SquareHeadCommented:
2 things you can try:

1. Do a response.write on your SQL statement and execute that directly in Access or Query Analyzer -- whichever DB you're using. See if your query is returning the email address value you expect.

2. Try the same thing with the RS value:

Response.write RS("txtEmailAddress")
Response.End

(Comment these out or remove them when you're done testing...)
0
 
cjinsocal581Commented:
Is txtEmailAddress the field name in your database?

Verify your filed name in the DB because that is where you are pulling it from.

0
 
net-workxAuthor Commented:
Putting in:
****************************
Response.write RS("txtEmailAddress")
Response.End
*****************************
Generates:
*****************************
Microsoft VBScript compilation error '800a0401'

Expected end of statement

/processing/process_send_contact_us.asp, line 54

objMail.To =   Response.write RS("txtEmailAddress")
------------------------------^
*******************************

It is pulling the correct email address from the DB as i have set the variable EmailAddress and when i do a response.write on this variable it prints out the correct address so its not an issue with the SQL command or DB connection or anything like that, its a problem actually transferring that variable into the objMail.To part of the script.

Thanks,
Carl
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SquareHeadCommented:
Yeah, this line is wrong...

objMail.To =   Response.write RS("txtEmailAddress")

Should be:

objMail.To =   RS("txtEmailAddress")
0
 
kiddangerCommented:
Carl...

They mean after this line:

EmailAddress = RS("txtEmailAddress")

...put:

Response.Write EmailAddress
Response.End

...which might be moot now since you said it does have the correct address.
I would put it like this so I can see invisible characters.
Response.Write "<span style=""background-color: #eef"">" & EmailAddress & "</span>" & vbCrLf
Response.End

You can make that easier as a subroutine:

sub dbug(str)
  Response.Write "<span style=""background-color: #eef"">" & str & "</span><br />" & vbCrLf
end sub

Call it with:
dbug EmailAddress

Your first error (line 58) appears to be this line:
objMail.Send

So, perhaps objMail.To is not your error because the error doesn't present itself until you try to send.

Also, you can probably use a single select statement instead of making 2 trips to the server.
This may work (untested)

sql = "SELECT tblProperty.intUserID, tblUsers.txtEmailAddress FROM
tblProperty, tblUsers WHERE tblProperty.id = " & PropertyID & " AND
tblUsers.id = tblProperty.intUserID"

or even (untested):

sql = "SELECT tblProperty.intUserID AS UserID, tblUsers.txtEmailAddress FROM
tblProperty, tblUsers WHERE tblProperty.id = " & PropertyID & " AND
tblUsers.id = UserID"

Don't call SELECT * if you only need on field.
0
 
kiddangerCommented:
Correction:
Don't call SELECT * if you only need ONE field.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now