Discussion Locked

ASP AND DATABASE HELP!

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is it possbile to send information through a form on a webpage in ASP and have the information stored into a Database (Access of SQL Server) and emailed to someone at the same time? If so, how do I do this?!?!?

8 replies

by ghousem

get the form contents and store in Database using INSERT and Use CDONTS.NewMail component to send e-mail, you need SMTP running on the Webserver.

Ghouse Mohiuddin Khadarabad

by jpalmera

Yes, it is very much possible. For an asp file "tosend.asp" having the source:

You can make a recieving file "esender.asp" with the following code:
<%@ Language=VBScript %>
<% 'the following code will input the email information into the table "emailtrack" containing fields "to","from","subject","body", in the sql database "emails" and the servermachiname "Myserver"
dim connectstr 'the connection string
connectstr="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Emails;Data Source=Myserver" 'if you are using NT integrated security and logged on an account with sufficient access privileges to the database
dim conn
set conn=server.createobject("adodb.connection")
with conn
.open connectstr
.execute "insert into emailtrack(to,from,subject,body) values('" & request.form("rcptaddr") & "','"& request.form("sndraddr") & "','" & request.form("subject") & "','" & request.form("body") & "')" 'assuming all the fields to be entered are strings
.close
end with
set conn=nothing
'to send an email
dim objsendmail
set objsendmail=server.CreateObject("cdonts.newmail")
objsendmail.To="reciever@someaddress.com"
objsendmail.From="sender@someaddress.com"
objsendmail.Subject="This is a test"
objsendmail.Body="This is the body of the test"
objsendmail.Send
%>

by webmaster

Yes Ryan,

The answer involves what is called ADO or Active Data Object from Microsoft.

Simple algorithm:

1. read the form variables (using request.form("fieldName"))
2. process the form data (strip any single quotes 3. from the input)
4. create the ADO connection to the database (usually through ODBC)
5. setup the SQL INSERT statement
6. execute the SQL
7. check the result

You can find specific examples of this on MSDN, 15 seconds, WROX, 2 guys from rolla, etc. Or if you're in a hurry, drop me an email.

Good luck.

by webmaster

Sorry, I didn't see your second requirement for sending email. Yes, as others have mentioned, the CDO or CDONTS component can send email using an SMTP server. Your script can do this after it stores the form contents in the database.

I use a component called ASPQMail from ServerObjects.com to do this same thing. Why? Because I bought this thing way back before CDO was available and I'm in the habit of using it.

This discussion is closed to new replies.