How do I send a confirmation e-mail once a web form is submitted?

How do I send a confirmation e-mail once a form has been submitted and the contents saved to my database?  Can somebody please give me an example or point me to some resource that shows how this is done?  My web server is IIS and the client's e-mail address is a required field on the form.
desmondgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Louis01Commented:
smtpUserName = ""
smtpPassword = ""
smtpServerName = "smtp.mydomain.com"
smtpServerPort = "25"
smtpFrom = "ValidUser@ValidDomain.com"

eMailTo = "user1@domain.com;user2@domain.com"
eMailCC = "otheruser@domain.com"

eMailSubject = "Test"

eMailBodyText = "Line 1" & chr(10) & chr(13) & "Line 2" & chr(13) &  vbcrlf & "Done!"
eMailBodyHTML = "Line 1<br>Line 2<br><br>Done!"

b_eMailFormatHTML = false


' Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Authenticate if necessary
if len(smtpUserName) > 1 then
      objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = smtpServerName
      objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtpPassword
end if

'Outgoing SMTP server configuration
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServerName
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpServerPort
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = smtpFrom

objCDOSYSMail.To = eMailTo
if eMailCC & "" <> "" then objCDOSYSMail.CC = eMailCC

objCDOSYSMail.Subject = eMailSubject

objCDOSYSMail.Fields("urn:schemas:mailheader:importance").Value = "high"

objCDOSYSMail.Fields.Update

if b_eMailFormatHTML then
      objCDOSYSMail.HTMLBody = eMailBody
else
      objCDOSYSMail.TextBody = eMailBody
end if

objCDOSYSMail.Send
0
stejamCommented:
What I would do is once the user clicks submit the page sends them to an ASP page which thanks them for submitting the form.  This page picks up the e-mail address using Request.Form and creates a recordset. You can then use any of the fields the user has just submitted to populate the e-mail (ie name etc.)

I've done similar with a lost password page; code adapted below to suit your situation:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
Dim rsConfirmMail
rsConfirmMail = "1"
If (Request.Form("email") <> "") Then
  rsConfirmMail = Request.QueryString("email")
End If
%>
<%
Dim rsConfirm
Dim rsConfirm_numRows

Set rsConfirm = Server.CreateObject("ADODB.Recordset")
rsConfirm.ActiveConnection = MM_cnAdHoc_STRING
rsConfirm.Source = "SELECT * FROM YOURTABLE WHERE email = '" + Replace(rsConfirmMail, "'", "''") + "'"
rsConfirm.CursorType = 0
rsConfirm.CursorLocation = 2
rsConfirm.LockType = 1
rsConfirm.Open()

rsConfirm_numRows = 0

'HERE WE CHECK TO MAKE SURE THE USERS EMAIL EXISTS, IF IT DOES, WE EMAIL IT
If NOT rsConfirm.EOF Then

      
      Dim objMail
      Set objMail = Server.CreateObject("CDONTS.NewMail")
            

      objMail.From = "YOUR_EMAIL"
      objMail.Subject = "SUBJECT"
      objMail.To = rsConfirm("email")
      objMail.Body = "YOUR MESSAGE IN HERE (CAN USE DATABASE FIELDS)"
      objMail.Send      
      Set ObjMail = Nothing

      x = "An e-mail has been sent confirming your registration bla bla message"

Else

      'IF THE EMAIL DOES NOT EXIST WE TELL THE BELOW
      x = "Sorry The Email Address You Entered Does Not Exist, Use the Back Button on Your Browser to Try Again"

End If
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<!--message from above-->
<p><%=x%></p>
</body>
</html>

0
desmondgAuthor Commented:
stejam,

Sorry for taking so long to provide feedback but I was out of office.  

At the line
Set objMail = Server.CreateObject("CDONTS.NewMail")
I get the error "Invalid class string".  I checked to see that IIS's SMTP server is installed and it is.  Any other suggestions?
0
desmondgAuthor Commented:
third:

I've tried the remote smtp server solution pointed to by your link and it seem to work except that the e-mails are not received.  They seem to be sent though.

I am awarding the points to you and will post another question trying to get help on why the e-mails are not received.

Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.