Link to home
Start Free TrialLog in
Avatar of net-workx
net-workxFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

SOLUTION
Avatar of SquareHead
SquareHead

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of net-workx

ASKER

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
Avatar of SquareHead
SquareHead

Yeah, this line is wrong...

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

Should be:

objMail.To =   RS("txtEmailAddress")
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correction:
Don't call SELECT * if you only need ONE field.