Submit Data to Database and Send Email Confirmation (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


nettop -> Submit Data to Database and Send Email Confirmation (4/29/2008 0:02:41)

I've seen the various posts for how to do this, but I am unable to get this default.asp page to work to submit 1 field of data to the database AND send a confirmation email. Here's the appropriate HTML:

<%
' FP_ASP ASP Automatically generated by a Frontpage Component. Do not Edit.

On Error Resume Next
Session("FP_OldCodePage") = Session.CodePage
Session("FP_OldLCID") = Session.LCID
Session.CodePage = 1252
Session.LCID = 1033
Err.Clear

strErrorUrl = ""

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
If Request.Form("VTI-GROUP") = "0" Then
	Err.Clear

	Set fp_conn =  Server.CreateObject("ADODB.Connection")
	FP_DumpError strErrorUrl, "Cannot create connection"

	Set fp_rs = Server.CreateObject("ADODB.Recordset")
	FP_DumpError strErrorUrl, "Cannot create record set"

	fp_conn.Open Application("email_newsletter_ConnectionString")
	FP_DumpError strErrorUrl, "Cannot open database"

	fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable
	FP_DumpError strErrorUrl, "Cannot open record set"

	fp_rs.AddNew
	FP_DumpError strErrorUrl, "Cannot add new record set to the database"
	Dim arFormFields0(1)
	Dim arFormDBFields0(1)
	Dim arFormValues0(1)

	arFormFields0(0) = "Email_newsletter"
	arFormDBFields0(0) = "Email_newsletter"
	arFormValues0(0) = Request("Email_newsletter")

	FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0

	If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then
		FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type"
	End If
	If Request.ServerVariables("REMOTE_HOST") <> "" Then
		FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name"
	End If
	FP_SaveFieldToDB fp_rs, Now, "Timestamp"
	If Request.ServerVariables("REMOTE_USER") <> "" Then
		FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name"
	End If

	fp_rs.Update
	FP_DumpError strErrorUrl, "Cannot update the database"

	fp_rs.Close
	fp_conn.Close

Set oMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
iConf.Fields.Update
Set oMail.Configuration = iConf
oMail.To 		= "info@foothillbiz4sale.com"
oMail.From 		= "webmaster@foothillbiz4sale.com"
oMail.Subject 		= "Subject - NEW Newsletter Request, Page 1 completed"
oMail.TextBody 		= "Hey Michele:  Someone has signed up to receive your newsletter from the homepage...  Tim"
oMail.Send
Set iConf = Nothing
Set Flds = Nothing

	Session("FP_SavedFields")=arFormFields0
	Session("FP_SavedValues")=arFormValues0
	Session.CodePage = Session("FP_OldCodePage")
	Session.LCID = Session("FP_OldLCID")
	Response.Redirect "email_newsletter.asp"

End If
End If

Session.CodePage = Session("FP_OldCodePage")
Session.LCID = Session("FP_OldLCID")

%>
<html>
............................

<form method="POST" action="--WEBBOT-SELF--" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">
<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"-->
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table14">
<tr>
<td>
<p align="justify">Receive the most comprehensive information about 	Businesses for Sale in the Grass Valley and Auburn Areas.<br>
<font color="#F4F2EB">
<span style="font-size: 4pt">
adfasdfdf</span></font></td>
</tr>
<tr>
<td>
<p align="center">
<input type="text" name="Email_newsletter" size="30" value="ENTER EMAIL ADDRESS">
<input type="submit" value="Submit" name="B3"><input type="reset" value="Reset" name="B4">
</td>
</tr>
<tr>
<td height="6"></td>
</tr>
<tr>
<td>Our team of 
										specialists track local businesses for 
										sale, sale statistics and provide 
										valuable articles, unavailable anywhere 
										else. We publish this information in our 
										Quarterly Newsletter. If you want to 
										keep ahead of market conditions, know 
										what is going on with businesses in the 
										area and receive informative articles 
										about business valuation and business 
										selling, subscribe to our newsletter - 
										it's free.</td>
</tr>
</table>
<input type="hidden" name="VTI-GROUP" value="0">
</form>




Spooky -> RE: Submit Data to Database and Send Email Confirmation (4/29/2008 2:43:30)

That looks ok, but as a test, does the email script work on its own first?




nettop -> RE: Submit Data to Database and Send Email Confirmation (4/29/2008 8:38:23)

Simple Question: What is the best way to test the script? I tried to create a page with just the info below, but that didn't work (http://www.foothillbiz4sale.com/test_email.asp). Thanks for your help, Tim

Set oMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
iConf.Fields.Update
Set oMail.Configuration = iConf
oMail.To = "info@foothillbiz4sale.com"
oMail.From = "webmaster@foothillbiz4sale.com"
oMail.Subject = "Subject - NEW Newsletter Request, Page 1 completed"
oMail.TextBody = "Hey Michele: Someone has signed up to receive your newsletter from the homepage... Tim"
oMail.Send
Set iConf = Nothing
Set Flds = Nothing




nettop -> RE: Submit Data to Database and Send Email Confirmation (5/2/2008 10:38:30)

I'm still trying to get this form to submit to the database AND send an email to a user to inform them that new data has been submitted. Any help would be most appreciated. Spooky suggested testing the script. I'm not exactly sure how to do that...any suggestions??? Thanks, Tim




Spooky -> RE: Submit Data to Database and Send Email Confirmation (5/2/2008 15:57:01)

You are posting it as a script? I just see code when I go there

<%
On ERROR RESUME NEXT

Set oMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
iConf.Fields.Update
Set oMail.Configuration = iConf
oMail.To = "info@foothillbiz4sale.com"
oMail.From = "webmaster@foothillbiz4sale.com"
oMail.Subject = "Subject - NEW Newsletter Request, Page 1 completed"
oMail.TextBody = "Hey Michele: Someone has signed up to receive your newsletter from the homepage... Tim"
oMail.Send
Set iConf = Nothing
Set Flds = Nothing

Response.write "Error code = " & err

%>




nettop -> RE: Submit Data to Database and Send Email Confirmation (5/2/2008 17:09:51)

That's my problem. I'm not exactly sure 'where' to run the script to test it. I tried it in an .asp page. Is there a program to run this in? Please advise, sorry to be so lame, Tim

quote:

<%
On ERROR RESUME NEXT

Set oMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
iConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
iConf.Fields.Update
Set oMail.Configuration = iConf
oMail.To = "info@foothillbiz4sale.com"
oMail.From = "webmaster@foothillbiz4sale.com"
oMail.Subject = "Subject - NEW Newsletter Request, Page 1 completed"
oMail.TextBody = "Hey Michele: Someone has signed up to receive your newsletter from the homepage... Tim"
oMail.Send
Set iConf = Nothing
Set Flds = Nothing

Response.write "Error code = " & err

%>




nettop -> RE: Submit Data to Database and Send Email Confirmation (5/2/2008 17:25:49)

I went down further in the html and at the <form> tag, I needed to replace what was there with the following and it worked fine...thanks for your patience with me...Tim:

<form method="POST" action="--WEBBOT-SELF--" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">
<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0">
<!--#include file="_fpclass/fpdbform.inc"-->




Spooky -> RE: Submit Data to Database and Send Email Confirmation (5/2/2008 20:14:42)

Just make a new asp page with that code on it (youll need to paste in code view)
It doesnt need any thing else on that page. Then just browse to it with your browser and it will try to do something! :)




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125