Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-08
3
Medium Priority
?
334 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 34

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 34

Expert Comment

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

604 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