Solved

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

Posted on 2013-01-08
3
328 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 32

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 32

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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 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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now