Solved

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

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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 …

688 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