[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2007-03-20
5
Medium Priority
?
206 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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 …
Suggested Courses

649 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