?
Solved

E-mail on Submit, not Page Load (vbscript)

Posted on 2013-01-08
3
Medium Priority
?
333 Views
Last Modified: 2013-01-08
I'm using the below code to to send e-mails and it works fine except it sends when I load the page and I really need it to send it when users click the submit button.  I tried the mailto: process in the form action, but my users don't have e-mail on their desktops and that looks for a default e-mail program to send the e-mail so it's not a solution.  Any help would be appreciated.

Dim sName, sEmail, sMessage
Dim oCdoMail, oCdoConf, sConfURL

sName = "DoNotReply@test.com"

sMessage = "An Request is awaiting your review."

Set oCdoMail = Server.CreateObject("CDO.Message")
Set oCdoConf = Server.CreateObject("CDO.Configuration")

sConfURL = "http://schemas.microsoft.com/cdo/configuration/"

with oCdoConf
	.Fields.Item(sConfURL & "sendusing") = 2
	.Fields.Item(sConfURL & "smtpserver") = "smtp.mail.fedex.com"
	.Fields.Item(sConfURL & "smtpserverport") = 25
	.Fields.Update
end with

with oCdoMail
	.From = sName
	.To = "test@test.com"
	.Subject = "Test"
	.TextBody = sMessage
	.HTMLBody = sMessage
	.Configuration = oCdoConf
	.Send
end with

Set oCdoConf = Nothing
Set oCdoMail = Nothing

Open in new window

0
Comment
Question by:Lord2FLI
[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
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 38756123
in your html for the page, create a button like this:

<input type="submit" name="email" value="Send Email" />

and now change your server side code to:

if Request.Form("email") = "Send Email" then
Dim sName, sEmail, sMessage
Dim oCdoMail, oCdoConf, sConfURL

sName = "DoNotReply@test.com"

sMessage = "An Request is awaiting your review."

Set oCdoMail = Server.CreateObject("CDO.Message")
Set oCdoConf = Server.CreateObject("CDO.Configuration")

sConfURL = "http://schemas.microsoft.com/cdo/configuration/"

with oCdoConf
	.Fields.Item(sConfURL & "sendusing") = 2
	.Fields.Item(sConfURL & "smtpserver") = "smtp.mail.fedex.com"
	.Fields.Item(sConfURL & "smtpserverport") = 25
	.Fields.Update
end with

with oCdoMail
	.From = sName
	.To = "test@test.com"
	.Subject = "Test"
	.TextBody = sMessage
	.HTMLBody = sMessage
	.Configuration = oCdoConf
	.Send
end with

Set oCdoConf = Nothing
Set oCdoMail = Nothing
end if

Open in new window


now the email should only send when the button is clicked!
0
 

Author Comment

by:Lord2FLI
ID: 38756152
Awesome!  worked like a charm, thank you very much!
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 38756156
my pleasure, glad I could help :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Suggested Courses

752 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