Solved

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

Posted on 2013-01-08
3
329 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
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

773 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