?
Solved

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

Posted on 2007-03-20
5
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 30

Accepted Solution

by:
third earned 750 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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