Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send form results to SQL Server and E-mail them too.

ASP 101

Send form results to SQL Server and E-mail them too.

by  DougP  Posted    (Edited  )
There are 2 .asp pages here. The first is a form to fill in.
Second saves first's forms data to SQL and E-mails the results to whom ever. This is tested and used in Front Page 2000 and IE 5.0 and (ASPemail on ISP)
-------------------- First .asp -------------
<html>
<%@ Language=VBScript %>
<head>
</head>

<body>
<form action="thankyou.asp" method=get>

<p align="center"><font size="5">Please fill in ALL the boxes</font></p>

<p align="left">First Name <input type="text" name="Firstname" size="20"></p>
<p align="left">Last name <input type="text" name="LastName" size="20"></p>
<p align="left"><input type="submit" value="Submit" name="Respond"><input type="reset" value="Reset" name="B2">áá
</p>
<p align="center">á
</form>


-------------------- Second = thankyou.asp --------------

<html>
<%@ Language=VBScript %>
<%Fname=request.querystring("FirstName")%>
<%Lname=request.querystring("LastName")%>
<%
Set Conn = server.CreateObject("ADODB.Connection")
Conn.Open "driver=SQL Server;server=server.com;uid=user1;pwd=pass1;database=databasename;"
Set RS1 = Conn.Execute("INSERT INTO dbo.BrochureRequests (FIRSTNAME, LASTNAME) VALUES ('" & Fname & "', '" & Lname & "')")
%>
<%
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "smtp.ij.net" ' Specify a valid SMTP server
Mail.From = "Webmaster@yoursite.com " ' Specify sender's address
Mail.FromName = "WEB Site Auto Responder" ' Specify sender's name

Mail.AddAddress "someone@yoursite.com ", "your name"
'Mail.AddReplyTo "info@veryhotcakes.com "
'Mail.AddAttachment "c:\images\cakes.gif"

Mail.Subject = "Put your subject here"
msg = "FIRSTNAME" & " " & Fname & Chr(13) & Chr(10)
msg = msg & "LASTNAME" & " " & Lname & Chr(13) & Chr(10)
Mail.Body = msg
On Error Resume Next
Mail.Send
If Err <> 0 Then
Response.Write "Error encountered: " & Err.Description
End If
%>

<head>
<title>Thank you</title>
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top