View Full Version : Email form in ASP.net
andreasberglind
09-22-03, 04:04 AM
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...
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"
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.