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 to email and DB

Status
Not open for further replies.

jesse123

Technical User
Apr 3, 2007
9
US
I looked at the FAQ's and came accross a sample on sending email and posting to DB.

I'm not sure how to make this work... Can some one give me a hand and check what I did?

<html>
<%@ Language=VBScript %>
<%Mname=request.querystring("name")%>
<%Mdate=request.querystring("date")%>
<%Mtime=request.querystring("time")%>
<%Maction=request.querystring("action")%>
<%Mload=request.querystring("load")%>
<%Mnotes=request.querystring("notes")%>
<%
Set Conn = server.CreateObject("ADODB.Connection")
Conn.Open "driver=SQL Server;server=server.com;database=VZThot_DB;"
Set RS1 = Conn.Execute("INSERT INTO dbo.Employee_Tracker (TechID, WRKDate, WRKTime, WRKAction, WRKLOAD, WRKNotes) VALUES ('" & Mname & "', '" & Mdate & "', '" & Mtime & "','" & Maction & "','" & Mload & "','" & Mnotes & "')")
%>
<%
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "smtp.ij.net"
Mail.From = "ME@ME.com"
Mail.FromName = "Jesse"

Mail.AddAddress "someone@yoursite.com"

Mail.Subject = "TEST"
msg = "name" & " " & Mname & Chr(13) & Chr(10)
msg = msg & "date" & " " & Mdate & Chr(13) & Chr(10)
msg = msg & "time" & " " & Mtime & Chr(13) & Chr(10)
msg = msg & "action" & " " & Maction & Chr(13) & Chr(10)
msg = msg & "load" & " " & Mload & Chr(13) & Chr(10)
msg = msg & "notes" & " " & Mnotes & 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>






also, how can I get it to work with cdosys?
 
Is the Persits.MailSender object installed on your web server?

Also, in my opinion, it would be much easier to learn these two things separately. I would concentrate on the database until you are getting good results and only then move on to work on the email... or the other way around. Learning them both at once seems like unnecessary complications.
 
Thanks for advice!

I took two different FAQ's and put them together and was able to get it to work! :)
 
> I took two different FAQ's and put them together
> and was able to get it to work! :)

How? It would serve this community better if you were to share your new-found knowledge. That way. somebody else with a similar issue could read your post and benefit in the same way.
 
This is what I ended up with... :)

<html>
<%@ Language=VBScript %>


<%Fname=request.Form("name")%>
<%Fdate=request.Form("date")%>
<%Ftime=request.Form("time")%>
<%Faction=request.Form("action")%>
<%Fload=request.Form("load")%>
<%Fnotes=request.Form("notes")%>

<%
'DNS CONNECTION
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "DSN=NAMEOFMYDNSHERE"
conn.Open
Dim strSQL, rs
strSQL = "Select NAMEOFFIELD from NAMEOFTABLEHERE"
set rs = Conn.Execute("INSERT INTO C:\Inetpub\wwwroot\DB\NAMEOFDBHERE.NAMEOFTABLEHERE (TechID, WRKDate, WRkTme, WRKAction, WRKNotes, WRKLOAD) VALUES ('" & Fname & "', '" & Fdate & "', '"& Ftime &"', '" & Faction & "', '" & Fnotes & "', '" & Fload & "')")
rs.Open strSQL, conn
%>

<%
'EMAIL BODY
MyBody = "Name: "& Fname & vbcrlf
MyBody = Mybody & "Date: "& Fdate & vbcrlf
MyBody = Mybody & "Time: "& Ftime & vbcrlf
MyBody = MyBody & "Action: "& Faction & vbcrlf
MyBody = MyBody & "Load: "& Fload & vbcrlf
MyBody = MyBody & Fnotes
%>

<%
'MAILING PART
Set MyMail = CreateObject("CDO.Message")
MyMail.From = "IPUTFROMHERE"
MyMail.To = "IPUTMAILTOHERE"
MyMail.Subject = "IPUTSUBJECTHERE"
MyMail.TextBody = IPUTBODYOFEMAIL
MyMail.Send
Set MyMail= nothing
Response.Write("Your e-mail has been sent.")
%>

<meta HTTP-EQUIV="REFRESH" content="0;URL=Techs/CA_TechEntry.asp">
<head>
<title>Thank you</title>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top