|
| |
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
Database / Email / CDONTS - 4/29/2002 14:16:44
I hope some one can help. I read in one of the older threads that you can have a form that updates a database and also sends email. I downloaded the white paper by Microsoft and followed it letter by letter using the Northwind example. I just cannot get it to work. I can access the form [url]www.amcotest.com/from.htm[/url], but when I click on submit I get a page cannot be displayed. Even when I use FrontPage on the live system and try to preview the email.asp file in the browser I get the same message. What could I be missing. I know that the server extensions are working because I created another test where you can send email and write to a text file and that worked. Thanks for any help.
|
|
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 8:52:33
Sorry about that. Its really [url]www.amcotest.com/form.htm[/url]. I ssem to have a lot of trouble spelling these days. Thanks.
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 9:15:05
Your initial form looks straight forward. Can you post your ASP code that is on email.asp?
|
|
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 9:41:48
<html> Here it is. It's straight from the Microsoft white paper. I wanted to see how it worked first before I started messing with the code for my own data fields since there are going to be alot of them. Thanks for looking! <head> <% '======================================================== ' When you press ENTER in a text box, a carriage return ' is created. A carriage return is represented by a ' Chr(13). Because this information will be displayed ' as HTML, replace the carriage returns with ' the <br> tag. '======================================================== Function ParseBody(strText) '================================================= ' This function replaces the Chr(13) with a <br> ' tag in whatever string is passed to it. '================================================= strText = Replace(strText, Chr(13), "<br>") ParseBody = strText End Function '======================================================== ' Send results to the database. ' This portion of the page sends the information ' from the form to the Northwind sample database. '======================================================== '======================================================== ' Variable declaration: ' myConnString = Connection string to database. ' myConnection = The database connection object. ' mySQL = The query string to be used. '======================================================== Dim myConnString Dim myConnection Dim mySQL '======================================================== ' Set up connection string. When you created the ' database connection in FrontPage called "Sample", ' FrontPage created an Application variable in the ' Global.asa file called "Sample_ConnectionString". ' ' Use that connection string by populating the ' myConnString variable with the value contained ' in the Application variable. ' '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' You can modify this to work with your database by ' changing "Sample_ConnectionString" to reflect your ' FrontPage database connection. For example, if you ' defined your connection in FrontPage as "Database1", ' you would change the following line to this: ' myConnString = Application("Database1_ConnectionString") '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% myConnString = Application("Sample_ConnectionString") '======================================================== ' When you are using custom ASP to set up a connection to ' a database, you use a Connection to connect to the ' database. The following line creates that connection and ' assigns the myConnection variable to contain the ' Connection object. '======================================================== Set myConnection = Server.CreateObject("ADODB.Connection") '======================================================== ' After the connection has been created, open it so that ' information can be written to the database. To do ' that, use the Open method and pass it the connection ' string that you defined earlier. '======================================================== myConnection.Open myConnString '======================================================== ' This is the SQL string that queries the database. ' In this example, Request.Form("[form_field]") ' pulls information from the form and populates the SQL ' string with it. ' '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' You can modify this SQL string to work with your own ' database by following this format. Pay special ' attention to the fact that spaces are not optional. ' ------------------------------------------------------- ' mySQL = "INSERT INTO [your_table_name] " ' mySQL = mySQL & "([database_field_names]) " ' mySQL = mySQL & "VALUES ('[form_field_names]')" ' ------------------------------------------------------- ' For more information about this, see the ' Customizing the Database Page section of this document.. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% mySQL= "INSERT INTO Employees " mySQL= mySQL & "(FirstName,LastName,Address,City,Region,PostalCode) " mySQL= mySQL & "VALUES ('" & Request.Form("FirstName") & "','" mySQL= mySQL & Request.Form("LastName") & "'" mySQL= mySQL & ",'" & Request.Form("Address") & "'" mySQL= mySQL & ",'" & Request.Form("City") & "','" mySQL= mySQL & Request.Form("Region") & "','" mySQL= mySQL & Request.Form("PostalCode") & "')" '======================================================== ' Execute the connection with the SQL string. ' This runs the SQL string against the database and inputs ' the information. '========================================================= myConnection.Execute mySQL '=== Close the connection. myConnection.Close '=== Set the connection equal to Nothing. '=== This frees resources used by it. Set myConnection = Nothing '=================================================================== ' Send the results to e-mail. ' Use CDONTS to create and send a message based on information ' entered into the form. The following lines compose and send ' the e-mail. '=================================================================== '==================================================================== ' Set up variables: ' myCDONTSMail = A CDONTS mail object. ' strFrom = A string containing the source e-mail address. ' strTo = A string containing the destination e-mail address. ' strSubject = A string containing the subject of the e-mail. ' strBody = A string containing the body of the e-mail. '==================================================================== Dim myCDONTSMail Dim strFrom Dim strTo Dim strSubject Dim strBody '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' Assign the source e-mail address. Change this to your e-mail ' address. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% strFrom="example@microsoft.com" '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' Assign the destination e-mail address. In this example, get the ' e-mail address from the form field called "EMail". ' You can customize this by removing the EMail form field and ' changing the following line to this: ' strTo="example@microsoft.com" ß Change this to your e-mail ' address. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% strTo=Request.Form("EMail") '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' The following line is the subject of the e-mail. You can change ' this to a subject that is customized to your liking. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% strSubject = "Send to E-mail and Database" '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' The following lines create the body of the message. This can be ' anything you want it to be. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% strBody="The following information was submitted:" & Chr(13) strBody = strBody & Request.Form("FirstName") & " " strBody = strBody & Request.Form("LastName") strBody = strBody & Chr(13) & Request.Form("Address") & Chr(13) strBody = strBody & Request.Form("City") & Chr(13) strBody = strBody & Request.Form("Region") & Chr(13) strBody = strBody & Request.Form("PostalCode") & Chr(13) strBody = strBody & Chr(13) & "Thank you for submitting your data." '==================================================================== ' The SET statement creates the CDONTS mail object in preparation ' for sending the e-mail message. '==================================================================== Set myCDONTSMail = CreateObject("CDONTS.NewMail") '==================================================================== ' The following line sends the mail message using the source e-mail, ' destination e-mail, subject, and body that were defined earlier. '==================================================================== myCDONTSMail.Send strFrom,strTo,strSubject,strBody '=== Set the CDONTS mail object to NOTHING to free resources. Set myCDONTSMail = Nothing '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' For information about how to customize the rest of this page, see the ' Customizing the Confirmation Page section of this document. Sections ‘ that are discussed in the Customizations section are delimited ' by percent signs. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %> </head> <body bgcolor="#FFCC99"> <p><font face="Verdana" color="#FF0000"><b>Thank you for submitting your information!<br> </b></font><font face="Verdana" size="2">You will receive an e-mail shortly. The e-mail was sent using the following information:</font></p> <b><b><font face="Verdana" size="2">Sent To: <% '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Response.Write Request.Form("email") '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %><br> From : Microsoft PSS Sample Page</font></b></p> <p><b><font face="Verdana" size="2">Subject: Send to Database and E-mail</font></b></p> <p><b><font face="Verdana" size="2">Content: <% '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ' Call the ParseBody function and pass the strBody string to it. ' This will replace the Chr(13) characters with <br> tags in the HTML. Response.Write(ParseBody(strBody)) '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %> </font></b></p> <hr noshade size="1" style="color: #000000"> <p> </p> </body> </html>
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 10:54:40
At first glance it looks like all your CDONTS code is in the <head> </head> section. Try moving it into the <body> section..... Hope it helps...
|
|
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 12:42:02
Thanks for answering. I did move the code around so that all of the CDONTS code was in the body but it gave me the same message. I'm convinced it's something on the server.
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 13:31:36
Try a quick test to see if CDONTS is configured correctly at the server. Build a new page and place this code inbetween the <body> </body> tags... <% Dim myMail Set myMail = CreateObject("CDONTS.NewMail") myMail.BodyFormat = 0 myMail.MailFormat = 0 myMail.From = "yourname@yourdomain.com" myMail.To = "yourname@yourdomain.com" myMail.Subject = "Test" myMail.Body = "Test" myMail.Send Set myMail = Nothing Response.Write("OK") %> This should check to see if CDONTS is working. Be sure to replace the To and From data to yours....
|
|
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 13:46:04
Did I need to put anything else on that page? I create a new page [url]www.amcotest.com/new.htm[/url] and all that happened was I came up with a blank page and nothing was in my email box. So the problem must be on my web server somewhere.
|
|
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 13:55:26
DUH! Sorry about that. I renamed the file to new.asp and it works! So, I guess CDONTS does work on the server. Now, I guess I need to look at the database part of this. I have a stupid question...do I need to have Access installed on the web server. I didn't think I needed because another test that I ran just using FrontPage to create a database worked. Do I need to do something with ODBC? Thanks for all your help!
|
|
|
|
trice
Posts: 135 Joined: 2/13/2002 From: Bensalem PA USA Status: offline
|
RE: Database / Email / CDONTS - 4/30/2002 20:21:34
I don't know how I did it, but I got it to work. Thanks for pointing me in the right direction.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|