LittleNFiesty
Technical User
I can't figure out why the below code is sending two emails. The code is to add a new record to an access db and send an email notifying that a new record was created, but instead of one email sent I always get 2, one blank and one with the correct info. I know it's something obvious but I just can't see it.
Here is the code:
<%
Dim refURL
refURL = Request.ServerVariables("HTTP_REFERER")
If (refURL = "") Then
'Do nothing because the page has no referer
Else
'Process the page, refURL is not empty
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsTLAdd 'Holds the recordset for the records the be updated
Dim strSQL 'Holds the SQL query to query the database
Dim Body 'Email Body
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DNS-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=XXXXXXXXX"
'Create an ADO recordset object
Set rsTLAdd = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with a SQL statement to query the database
strSQL = "SELECT Tbl_RegistrationList.* FROM Tbl_RegistrationList;"
'Set the cursor type we are using so we can navigate through the recordset
rsTLAdd.CursorType = 2
'Set the lock type so the the recrod is loced by ADO when it is updated
rsTLAdd.LockType = 3
'Open the recordset with SQL query
rsTLAdd.Open strSQL, adoCon
'Tell the recordset we are adding a new record to it
rsTLAdd.AddNew
'Update record to the recordset
rsTLAdd.Fields("Name") = Request.Form("Name")
rsTLAdd.Fields("Company") = Request.Form("Company")
rsTLAdd.Fields("Address1") = Request.Form("Address1")
rsTLAdd.Fields("Address2") = Request.Form("Address2")
rsTLAdd.Fields("City") = Request.Form("City")
rsTLAdd.Fields("State") = Request.Form("State")
rsTLAdd.Fields("ZipCode") = Request.Form("Zip_Code")
rsTLAdd.Fields("Country") = Request.Form("Country")
rsTLAdd.Fields("Phone") = Request.Form("Phone")
rsTLAdd.Fields("Email") = Request.Form("Email")
rsTLAdd.Fields("RegistrationDate") = CDate(FormatDateTime(Now,2))
'Tell the recordset we are updating record
rsTLAdd.Update
'Email coding:
'current date and IP address for email
datCurrDate = Now
StrReferer = Request.ServerVariables ("HTTP_REFERER")
Body = Body & "Registered User:" & vbCrLf & Request.Form("Email") & vbCrLf & Request.Form("Name") & vbCrLf & Request.Form("Company") & vbCrLf & Request.Form("Address1")& vbCrLf & Request.Form("Address2") & vbCrLf & Request.Form("City")& vbCrLf & Request.Form("State") & vbCrLf & Request.Form("ZipCode") & vbCrLf & Request.Form("Country") & vbCrLf & vbCrLf
Body = Body & "The Above was submitted via your online form: " & Request.Form("000FormInfo") & vbCrLf & "At: " & strReferer & vbCrLf & "On: " & datCurrDate & vbCrLf & "By: " & Request.ServerVariables("REMOTE_ADDR") & vbCrLf & vbCrLf
Dim ObjSendMail
Dim iConf
Dim Flds
Set ObjSendMail=Server.CreateObject("CDO.Message")
Set iConf=CreateObject("CDO.Configuration")
Set Flds=iConf.Fields
Flds("
Flds("Flds.Update
Set ObjSendMail.Configuration=iConf
ObjSendMail.To="webmaster@someone.com"
ObjSendMail.From="someone@someone.com"
ObjSendMail.Subject=request.form("000FormInfo")
ObjSendMail.TextBody=Body
ObjSendMail.Send
Set ObjSendMail=Nothing
'Reset server objects
rsTLAdd.Close
Set rsTLAdd = Nothing
Set adoCon = Nothing
'Redirect to page
Response.Redirect "../Page.asp"
End If
%>
Here is the code:
<%
Dim refURL
refURL = Request.ServerVariables("HTTP_REFERER")
If (refURL = "") Then
'Do nothing because the page has no referer
Else
'Process the page, refURL is not empty
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsTLAdd 'Holds the recordset for the records the be updated
Dim strSQL 'Holds the SQL query to query the database
Dim Body 'Email Body
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DNS-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=XXXXXXXXX"
'Create an ADO recordset object
Set rsTLAdd = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with a SQL statement to query the database
strSQL = "SELECT Tbl_RegistrationList.* FROM Tbl_RegistrationList;"
'Set the cursor type we are using so we can navigate through the recordset
rsTLAdd.CursorType = 2
'Set the lock type so the the recrod is loced by ADO when it is updated
rsTLAdd.LockType = 3
'Open the recordset with SQL query
rsTLAdd.Open strSQL, adoCon
'Tell the recordset we are adding a new record to it
rsTLAdd.AddNew
'Update record to the recordset
rsTLAdd.Fields("Name") = Request.Form("Name")
rsTLAdd.Fields("Company") = Request.Form("Company")
rsTLAdd.Fields("Address1") = Request.Form("Address1")
rsTLAdd.Fields("Address2") = Request.Form("Address2")
rsTLAdd.Fields("City") = Request.Form("City")
rsTLAdd.Fields("State") = Request.Form("State")
rsTLAdd.Fields("ZipCode") = Request.Form("Zip_Code")
rsTLAdd.Fields("Country") = Request.Form("Country")
rsTLAdd.Fields("Phone") = Request.Form("Phone")
rsTLAdd.Fields("Email") = Request.Form("Email")
rsTLAdd.Fields("RegistrationDate") = CDate(FormatDateTime(Now,2))
'Tell the recordset we are updating record
rsTLAdd.Update
'Email coding:
'current date and IP address for email
datCurrDate = Now
StrReferer = Request.ServerVariables ("HTTP_REFERER")
Body = Body & "Registered User:" & vbCrLf & Request.Form("Email") & vbCrLf & Request.Form("Name") & vbCrLf & Request.Form("Company") & vbCrLf & Request.Form("Address1")& vbCrLf & Request.Form("Address2") & vbCrLf & Request.Form("City")& vbCrLf & Request.Form("State") & vbCrLf & Request.Form("ZipCode") & vbCrLf & Request.Form("Country") & vbCrLf & vbCrLf
Body = Body & "The Above was submitted via your online form: " & Request.Form("000FormInfo") & vbCrLf & "At: " & strReferer & vbCrLf & "On: " & datCurrDate & vbCrLf & "By: " & Request.ServerVariables("REMOTE_ADDR") & vbCrLf & vbCrLf
Dim ObjSendMail
Dim iConf
Dim Flds
Set ObjSendMail=Server.CreateObject("CDO.Message")
Set iConf=CreateObject("CDO.Configuration")
Set Flds=iConf.Fields
Flds("
Flds("Flds.Update
Set ObjSendMail.Configuration=iConf
ObjSendMail.To="webmaster@someone.com"
ObjSendMail.From="someone@someone.com"
ObjSendMail.Subject=request.form("000FormInfo")
ObjSendMail.TextBody=Body
ObjSendMail.Send
Set ObjSendMail=Nothing
'Reset server objects
rsTLAdd.Close
Set rsTLAdd = Nothing
Set adoCon = Nothing
'Redirect to page
Response.Redirect "../Page.asp"
End If
%>