Posted By

rts_dev on 01/04/11


Tagged


Versions (?)

VB.NET for a Basic ASP.net Contact Form (Includes Full Name, Email, and Message Fields)


 / Published in: VB.NET
 

Make sure to change the partial class name. It's based on the page name. Also, don't forget to create a ThankYou.aspx page!

  1. Imports System.Net.Mail
  2. Imports System.Net.Configuration
  3. Partial Class _Default
  4. Inherits System.Web.UI.Page
  5. Protected Sub btnSumbit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSumbit.Click
  6. Dim client As New SmtpClient("RS-E133-V.bckcom.com")
  7. Dim mmsg As New MailMessage("[email protected]", "[email protected]")
  8. mmsg.IsBodyHtml = True
  9. mmsg.Body &= "<html>"
  10. mmsg.Body &= "<body>"
  11. mmsg.Body &= "<style type&='text/css'>body{font:arial, verdana; font-size:11pt;}b{font-size:10pt; color:blue;}</style>"
  12. mmsg.Body &= "<b>Time Submited: </b> " + DateTime.Now
  13. mmsg.Body &= "<br />"
  14. mmsg.Body &= "Sentby: " + tbName.Text
  15. mmsg.Body &= "<br />"
  16. mmsg.Body &= "<hr />"
  17. mmsg.Body &= "<b>First Name: </b> " + tbName.Text
  18. mmsg.Body &= "<br />"
  19. mmsg.Body &= "<b>Email: </b> " + tbEmail.Text
  20. mmsg.Body &= "<br />"
  21. mmsg.Body &= "<b>Message: </b> " + tbMessage.Value
  22. mmsg.Body &= "<br />"
  23. mmsg.Subject &= "Subject" 'Type in Subject Here
  24. 'Now, to send the message, use the Send method of the SmtpMail class
  25. If IsValid Then
  26. client.Send(mmsg)
  27. Response.Redirect("~/Thankyou.aspx") 'Where the form should redirect to, don't forget to create this page
  28. End If
  29. End Sub
  30. End Class

Report this snippet  

You need to login to post a comment.