ASP.NET Create Contact Us Form Page

In this example i'm explaining how to Create Contact Us Form In Asp.Net Using C# And VB.NET.

ContactUs Page is essential part of any web site or application, through which users send comments or feedback about site or can contact site admins.

To create contact form in web applications we need a working SMTP server through which aspx page can send the form data to admins email id.

For this example i'll use Gmail account to send mail on behalf of application to admins gmail id.

Place three Textbox on the page for users to input their name, email id, and subject, add another textbox for entering feedback or comment and set it's TextMode property to MultiLine.

Add RequiredFieldValidators to ensure entry in every field, add one button to send the mail.

   1:  <html xmlns="">
   2:  <head runat="server">
   3:  <title>Contact Us</title>
   4:  <link href="StyleSheet.css" rel="stylesheet" type="text/css" />  
   5:  </head>
   6:  <body>
   7:  <form id="ContactForm" runat="server">
   8:  <div>
   9:   <fieldset>
  10:  <legend>Contact us</legend> 
  11:  <div class='short_explanation'>* required fields</div>
  13:  <div class='container'>
  14:  <asp:Label ID="lblName" runat="server" 
  15:             Text="Your Name*:" CssClass="label"/><br/>
  16:  <asp:TextBox ID="txtName" runat="server"/>
  17:  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
  18:                              runat="server" 
  19:                              ControlToValidate="txtName" 
  20:                              ErrorMessage="Enter Your Name" 
  21:                              SetFocusOnError="True">*
  22:  </asp:RequiredFieldValidator><br />
  23:  </div>
  25:  <div class='container'>
  26:  <asp:Label ID="lblEmail" runat="server" 
  27:             Text="Email*:" CssClass="label"/><br/>
  28:  <asp:TextBox ID="txtMail" runat="server"/>
  29:  <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 
  30:                              runat="server" 
  31:                              ControlToValidate="txtMail" 
  32:                              ErrorMessage="Please Provide 
  33:                                           Your Email Address" 
  34:                              SetFocusOnError="True">*
  35:  </asp:RequiredFieldValidator><br />
  36:  </div>
  38:  <div class='container'>
  39:  <asp:Label ID="lblSubject" runat="server" 
  40:             Text="Subject*:" CssClass="label"/><br/>
  41:  <asp:TextBox ID="txtSubject" runat="server"/>
  42:  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" 
  43:                              runat="server" 
  44:                              ControlToValidate="txtSubject" 
  45:                              ErrorMessage="Please provide 
  46:                                           reason to contact us" 
  47:                              SetFocusOnError="True">*
  48:  </asp:RequiredFieldValidator><br />
  49:  </div>
  51:  <div class='container'>
  52:  <asp:Label ID="lblMessage" runat="server" 
  53:             Text="Feedback:" CssClass="label"/><br/>
  54:  <asp:TextBox ID="txtMessage" runat="server" 
  55:               TextMode="MultiLine" Width="268px"/>
  56:  <asp:RequiredFieldValidator ID="RequiredFieldValidator4" 
  57:                              runat="server" 
  58:                              ControlToValidate="txtMessage" 
  59:                              ErrorMessage="Write your feedback" 
  60:                              SetFocusOnError="True">*
  61:  </asp:RequiredFieldValidator><br />
  62:  </div>
  64:  <div class='container'>
  65:  <asp:Button ID="btnSubmit" runat="server" 
  66:              Text="Submit" onclick="btnSubmit_Click"/>
  67:  </div>
  68:  <asp:ValidationSummary ID="ValidationSummary1" 
  69:                         runat="server" CssClass="error"/>
  70:  </fieldset>
  71:  <asp:Label ID="Label1" runat="server" Text=""/>
  72:  </div>
  73:      </form>
  74:  </body>
  75:  </html>

Write following code in Click Event of submit button.

using System;
using System.Net.Mail;
protected void btnSubmit_Click(object sender, EventArgs e)
        MailMessage feedBack = new MailMessage();
        feedBack.From = new MailAddress("");
        feedBack.Subject = txtSubject.Text;

        feedBack.Body = "Sender Name: " + txtName.Text + "

Sender Email: " + txtMail.Text + "

" + txtMessage.Text; feedBack.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = ""; //Or Your SMTP Server Address smtp.Port = 587; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential("", "YourGmailPassword"); //Or your Smtp Email ID and Password smtp.Send(feedBack); Label1.Text = "Thanks for contacting us"; }

Protected Sub btnSubmit_Click(sender As Object, e As EventArgs)
 Dim feedBack As New MailMessage()
 feedBack.From = New MailAddress("")
 feedBack.Subject = txtSubject.Text

 feedBack.Body = (("Sender Name: " + txtName.Text & "

Sender Email: ") + txtMail.Text & "

") + txtMessage.Text feedBack.IsBodyHtml = True Dim smtp As New SmtpClient() smtp.Host = "" 'Or Your SMTP Server Address smtp.Port = 587 smtp.EnableSsl = True smtp.Credentials = New System.Net.NetworkCredential("", "YourGmailPassword") 'Or your Smtp Email ID and Password smtp.Send(feedBack) Label1.Text = "Thanks for contacting us" End Sub

Contact Us Form In Asp.Net

Download Sample Code

If you like this post than join us or share


prashant said...

Amit thanks for adding Contact us page i really need it,
but I dont understand how to use vb code so please tell me the procedure where the vb code put down.

amiT jaiN said...

@Prashant: I have attached source code for this article which includes C# And VB versions of page
download and let me know if you need any further assistance

prashant said...

Thanks Amit,
Its working good for me.
Add more code related to make good Website, and if possible Add the code for professional menu


prashant said...

Amit, I want code for forgotten password and change password please help me.

amiT jaiN said...

Please refer Forgot Password Page In Asp.Net

Anonymous said...

can u please tell me .. if i make form in html format then how i send the email using c#...its urgent...

please reply me on

amiT jaiN said...

@Above: i didn't get your question, even my contact form is in HTML format only

Anonymous said...

hi i have 1 template which have there own contact us form gow to edit and write code for that please mail me at

Anonymous said...

Thanks for informations. Where is the css file? I downloaded files but I didn't find it.

manish kumar said...

thank you

Anonymous said...


Rose Rose said...

thank you

can i using this without use SMTP server ??

i want the message show in gridview in admin page can create like this..

Find More Articles