Click to See Complete Forum and Search --> : Sending Email Using ASP


Chamark
12-20-2006, 06:19 AM
I have a form that the user fills out and I want to send an email when the user clicks the submit button. How would I incorporate the following code to only send when the submit button is clicked? Thanks in advance for any help!!

<body>
<%
Dim objNewMail
Set objNewMail = CreateObject("CDO.Message")
With ObjNewMail
'This section provides the configuration information for the remote SMTP server.
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="10.14.83.20"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Configuration.Fields.Update
'End remote SMTP server configuration section==
.From = "me@myserver.com"
.To = "you@yourserver.com"

.Subject = "Test Email"
.HTMLBody = "this is a test"
.Send
End With
set objNewMail = Nothing
%>
</body>

russell
12-20-2006, 10:33 AM
put it all in a Sub() then call the sub if the form has been submitted


<%
If len(Request.Form("nameOfOneOfYourFormFields")) Then
SendMail
End If

Sub SendMail()
Dim objNewMail
Set objNewMail = CreateObject("CDO.Message")

With ObjNewMail
'This section provides the configuration information for the remote SMTP server.
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="10.14.83.20"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Configuration.Fields.Update
'End remote SMTP server configuration section==
.From = "me@myserver.com"
.To = "you@yourserver.com"

.Subject = "Test Email"
.HTMLBody = "this is a test"
.Send
End With

set objNewMail = Nothing
End Sub
%>

Chamark
12-20-2006, 11:33 AM
OK. Here is what I put in after the form code. Then (I'm using Dreamweaver 8) I put in the behavior Onsubmit SendMail(). The data makes it to the database, but no email. I am sending the email to myself obviously.

<%
If len(Request.Form("BadgeID")) Then
SendMail
End If

Sub SendMail()
Dim objNewMail
Set objNewMail = CreateObject("CDO.Message")

With ObjNewMail
'This section provides the configuration information for the remote SMTP server.
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="11.11.11.11"
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Configuration.Fields.Update
'End remote SMTP server configuration section==
.From = "A322146"
.To = "A322146"

.Subject = "Test Email"
.HTMLBody = "this is a test"
.Send
End With

set objNewMail = Nothing
End Sub
%>

russell
12-20-2006, 11:43 AM
take out the behavior. just let the form get submitted. if badgeid has a value, the email will go

Chamark
12-20-2006, 07:43 PM
Thanks Russell. As usual you know your stuff. This really helped me out and I appreciate your patience. I learned something to boot.

russell
12-20-2006, 09:24 PM
glad to help