Login | Register  

Contact Form in ASP.NET

by Scud   Tuesday, July 03, 2007 Rating:
 Vote this news:


It's easier than Classic ASP to send email within an ASP.NET application. All you need is to use SmtpMail class in your application. Current example uses SmtpMail class to send a web message to your email. You may use it with copying and edit a few lines in code. 

Do not forget to edit lines covered under with yellow.

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<% @Import Namespace="System.Web.Mail" %>
<script language="vb" runat="server">

Sub sendFormButton_Click(sender as Object, e as EventArgs)

  Dim ojMailCom as New MailMessage()
  ojMailCom.To = "
info@YOUR_DOMAIN_NAME"
  ojMailCom.From = txtsenderEmail.Text
  ojMailCom.BodyFormat = MailFormat.Text 'MailFormat.Html for HTML emails
  'Set the priority - options are High, Low, and Normal
  ojMailCom.Priority = MailPriority.Normal ' can be change from low to High
  ojMailCom.Subject = "Contact form message"

  ojMailCom.Body = "Message written by: " & txtsenderName.Text & vbnewline & txtsenderMessage.Text
  SmtpMail.SmtpServer = "MAIL.YOUR_DOMAIN_NAME"
  SmtpMail.Send(ojMailCom)
  contactEmail.Visible = false
  viewMailSent.Visible = true
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact Form in ASP.NET</title>
</head>
<body>

<h1>Contact Form in ASP.NET</h1>
 <asp:panel id="contactEmail" runat="server">
    <form runat="server">
      <span style="font:11px Arial, Helvetica, sans-serif; font-weight:bold">Name:</span>
        <asp:textbox id="txtsenderName" runat="server" />
  <br />

      <span style="font:11px Arial, Helvetica, sans-serif; font-weight:bold">Email Address:</b>
      <asp:textbox id="txtsenderEmail" runat="server" />
  <BR />
      <span style="font:11px Arial, Helvetica, sans-serif; font-weight:bold">Message:</span>
  <br />
      <asp:textbox id="txtsenderMessage" TextMode="MultiLine" Columns="60" Rows="7" runat="server" />
  <br /><br />
      <asp:button runat="server" id="sendFormButton" Text="Send Form!" OnClick="sendFormButton_Click" />
    </form>
  </asp:panel>


  <asp:panel id="viewMailSent" runat="server" Visible="False">
  <span style="font:11px Arial, Helvetica, sans-serif; font-weight:bold">
    Thanks for your kind message!</span>
  </asp:panel>
</body>
</html>

Happy coding with dotnetindex.com





Dotnetindex.com is listed with 411asp.net
Dotnetindex.com is listed with aspin.com
Dotnetindex.com is listed with jspin.com
PHP, ASP, .NET, JSP Resources, Reviews







page counter
Copyright © 2007 Powered by GNews Publisher Positive. All rights reserved. Contact Us - Load Time: 0.08 second(s)