PDA

View Full Version : Multiple Emails with script


SFC
02-24-2009, 06:04 PM
I would like to use one script to send an email to me with the submitted information and a response email to the person who submitted the information. I am currently using the following script:

<!--
METADATA
TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library"
-->
<%



Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "local.server"
.Update
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = "email@email.com"
.To = "email@email.com"
.Subject = "Info Request from Church Website"
.TextBody = Trim(Request.Form("name")) & vbcrlf + vbcrlf & Trim(Request.Form("EmailFrom"))
.Send

End With


Response.Redirect("../index.shtml")


%>

This script works great for sending me the submitted information. What do I need to do to modify this so I can send a response message to the submitter?

Thank you for your help!

whammy
02-26-2009, 10:51 PM
First of all you need to retrieve the person's email that was submitted (I'm assuming this is "EmailFrom"), then just CC your email address as well when you send the message:


<%
// Validate proper email syntax
Function IsEmail(str)
Dim ieRegEx
Set ieRegEx = New RegExp
ieRegEx.Pattern = "^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
IsEmail = ieRegEx.Test(str)
End Function

Dim EmailFrom

EmailFrom = Request.Form("EmailFrom") // Store the user's address in a variable

If IsEmail(EmailFrom) Then

// Send the email!

Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "local.server"
.Update
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = "email@email.com"
.To = EmailFrom // Send it to the user's email we got earlier
.Cc = "you@youremailaddress.com" // Copy the message to yourself
.Subject = "Info Request from Church Website"
.TextBody = Trim(Request.Form("name")) & vbcrlf + vbcrlf & EmailFrom
.Send

End With

Response.Redirect("../index.shtml")
Else
// Redirect them with a querystring error message you can check for!

Response.Redirect ("../index.shtml?email=invalid")
End If
%>


If you wanted to display an error message on "index.shtml" you could change the page to an .asp extension and check for the querystring value "email", i.e.:


<% If Request.Querystring("email") = "invalid" Then Response.Write "<p><strong>Please enter a valid email address!</strong></p>" %>


If you go that route don't forget to change the references to "index.shtml" to "index.asp". ;)

shakir
03-02-2009, 04:35 PM
For response Emil why don't try to send again after this script by changing from , to.. repeat the send action by interchanginf from and to .. so in each submitting the script will send 2 mail.. one to him and other to the sender

whammy
03-03-2009, 07:09 AM
I think what shakir is getting at is you can send the email to whoever needs the information - and right after that (on the same ASP page) send a message the the user thanking them for their email (and perhaps promoting a product or service), with a copy of the message written below it.

If you want to format the posted information easily I learned an efficient way of doing it a few years ago by just building a big string out of it (probably with help from these forums - most likely Dave Clark or another great programmer):


For i = 1 to Request.Form.Count
fieldName = Request.Form.Key(i)
fieldValue = Request.Form.Item(i)
If fieldValue <> "" Then
objEmail.TextBody = objEmail.TextBody & (fieldName & ": " & fieldValue & vbCrLf)
End If
Next