Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send email onSubmit???

Status
Not open for further replies.

SmokinRR

Technical User
May 26, 2004
56
0
0
US
Hello everyone,
I'm fairly new to .asp and am having a bit of trouble with the following task. I have a page that sends an email out to a group of people within the organization using CDONTs and it functions, somewhat. I want the email to be sent when the form is submitted, currently the code executes as soon as the page loads. Here is the code, I just need to know how to make it execute onSubmit rather then whent he page loads.

<%
Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")


myMail.From = "User" & " <" & "user@mycomp.com" & ">"
myMail.To = "me@mycomp.com"
myMail.BCC = Request("hfEmail")
myMail.Subject = "Reminder"
myMail.BodyFormat = 0
myMail.Body = "Body"
myMail.MailFormat = 0
On error resume next
myMail.Send
Set objMail = nothing
End If
%>

Any help would be appreciated!

J
 
I assume the form post back to itself, if so, try this:

<%
If Request.Form.Count > 0 Then
Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")


myMail.From = "User" & " <" & "user@mycomp.com" & ">"
myMail.To = "me@mycomp.com"
myMail.BCC = Request("hfEmail")
myMail.Subject = "Reminder"
myMail.BodyFormat = 0
myMail.Body = "Body"
myMail.MailFormat = 0
On error resume next
myMail.Send
Set objMail = nothing

End If
%>
 
or do it in two pages...here is the code...

formpage.htm
Code:
<html>
<body>
<form name="myform" action="mail.asp" method="POST">
<input type="text" name="fromAdd">
<input type="text" name="toAdd">
<input type="text" name="bccAdd">
<input type="text" name="mailsubject">
<input type="textarea" name="mailbody">
<input type="submit" name="submit" value="send mail">
</form>
</body>
</html>


mail.asp

Code:
 <%
    Dim myMail
    Set myMail = CreateObject("CDONTS.NewMail")


    myMail.From = "User" & " <" & "request("fromAdd")" & ">"
    myMail.To = request("toAdd")
    myMail.BCC = Request("bccAdd")
    myMail.Subject = request("mailsubject")
    myMail.BodyFormat = 0
    myMail.Body = Request("mailbody")    
    myMail.MailFormat = 0
    On error resume next
    myMail.Send
    Set objMail = nothing
    End If
%>

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top