Solved

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

Posted on 2007-03-20
5
200 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 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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/…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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