Solved

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

Posted on 2007-03-20
5
193 Views
Last Modified: 2010-04-20
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.
0
Comment
Question by:desmondg
5 Comments
 
LVL 30

Accepted Solution

by:
third earned 250 total points
ID: 18757898
0
 
LVL 11

Expert Comment

by:Louis01
ID: 18757972
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
 
LVL 3

Expert Comment

by:stejam
ID: 18759491
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
 

Author Comment

by:desmondg
ID: 18794979
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
 

Author Comment

by:desmondg
ID: 18819898
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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now