Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: activating mailobj when adding from a form


Message #1 by "Mark" <marks20101@c...> on Fri, 3 May 2002 20:14:08
Hello, the folling code adds items to a db, but I want to trigger 
("CDONTS.NewMail")mailObj to be sent to(at bottom of code), i.e
(EmailToAddress = Request.Form("EmailFrom"). How can a set a condition to 
send mail, and do I even put this in this page or should I put this in the 
actual form(txtboxes)page?
<%
Dim MyConn, RS, strFirstName, strLastName, strUserName, 
strPassword,strEmailFrom

'grab the form contents
strFirstName = Request.Form("txtFirstName")
strLastName = Request.Form("txtLastName")
strUserName = Request.Form("txtUserName")
strPassword = Request.Form("txtPassword")
strEmailFrom = Request.Form("txtEmailFrom")
'strEmailSubject = Request.Form("txtSubject")
'strMessage= Request.Form("txtMessage")
 
Set MyConn=Server.CreateObject("ADODB.Connection")

Set RS=Server.CreateObject("ADODB.RecordSet")

MyConn.Open "getdata"

RS.Open "Select * From test_view", MyConn, adOpenDynamic, 
adLockPessimistic, adCMDText

'open both RecordSets
RS.AddNew
RS("FirstName")= strFirstName
RS("LastName")= strLastName
RS("EmailFrom") = strEmailFrom
'RS("EmailSubject") = strEmailSubject
'RS("message") = strMessage
RS("UserName")= strUserName
RS("Password")= strPassword
RS.Update

'Clean up
RS.Close

MyConn.Close
Set RS = Nothing

set MyConn = Nothing
%>

An e-mail has been sent to your mailbox (<%=request.form("txtEmailFrom")%
>).
'I WANT TO TRIGGER EMAIL TO BE SENT???
<%

Dim EmailFromAddress, EmailToAddress, Subject, Body
EmailFromAddress = "contact@p..."
EmailToAddress = Request.Form("EmailFrom")
Subject = Request.Form("EmailSubject")
Body = Request.Form("message")

Set MailObj = Server.CreateObject ("CDONTS.NewMail")
MailObj.BodyFormat = 1 
MailObj.MailFormat = 0
MailObj.Send EmailFromAddress, EmailToAddress, Subject, Body
Response.Write "Your Comments Have Been Sent ! "
%>

THIS still adds to db but I get this ERROR and no mail was sent:

Microsoft VBScript runtime error '800a01f4' 
Variable is undefined: 'MailObj' 
/contacts/addtodatabase.asp, line 64

Thanks! 

  Return to Index