Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Email form in ASP.net


Email form in ASP.net

Reply
  #1 (permalink)  
Old 09-22-03, 04:04 AM
andreasberglind andreasberglind is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Sweden
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Email form in ASP.net

I have this form, and it is submitted to another page, working fine, thanks for the help everyone.
However, when one problem is solved, another arises.
In the second page, with all the answers from the form, I want to put a button which emails the form to a specified address.
How would I do this. I simply cannot get it to work.

Please help...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-04-04, 07:27 AM
chirag's Avatar
chirag chirag is offline
Newbie Coder
 
Join Date: May 2004
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Put folowing button in your web form that you want to mail...

<asp:Button id="btnSendMail" text="Send Mail!" OnClick="btnSendMail_OnClick" runat="server" />

put this code in your page
don't forget to replace localhost with your smtp server address...


<script language="VB" runat="server">
Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
Dim myMessage As New MailMessage
Dim myMail As SmtpMail
Dim strEmail As String

If Page.IsValid() Then
strEmail = "someone@yourdoamin.com" myMessage.From = "webmaster@" & Request.ServerVariables("SERVER_NAME")
myMessage.To = strEmail
myMessage.Subject = "E-mail Sample from ASP 101!"
myMessage.Body = "This message was sent from sample code by " & _
"http://www.asp101.com. It is used to show people how " & _
"to send e-mail from an ASP+ page. This mail was sent " & _
"from " & Request.ServerVariables("SERVER_NAME") & ". " & _
vbCrLf & vbCrLf & _
"This email was sent to " & strEmail & "."

' Doesn't have to be local... just enter your
' SMTP server's name or ip address!
myMail.SmtpServer = "localhost"
myMail.Send(myMessage)

frmEmail.Visible = false
lblUserMessage.Text = "Your message has been sent to " & strEmail & "."
End If
End Sub
</script>

hope this helps.

you can find complete source code for this example at
"http://www.asp101.com"

Last edited by chirag; 05-04-04 at 07:33 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Submit form in asp.net andreasberglind ASP.NET 8 11-18-03 08:33 AM
Preventing email form abuse LunarOrbit Perl 3 10-04-03 10:55 PM
send email when sending form (asp) bmatth1 Script Requests 0 09-30-03 06:52 AM
Email in ASP.net andreasberglind ASP.NET 1 09-17-03 10:37 AM
Free .ASP 'tell a friend' email form needed, preferably with multiple friend spaces retrocom Script Requests 0 08-23-03 01:44 PM


All times are GMT -5. The time now is 12:22 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.