Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Part 142 - Contact us page using and c# continued

Suggested Videos
Part 139 - How to upload and download files using and c#
Part 140 - Creating an image gallery using and c#
Part 141 - Contact us page using and c#

In Part 141, we discussed designing "contact us" page. In this video, we will implement the server side code. Once the form is submitted, an email should be sent to the support group. The email should contain all the details that are entered in the contact us form.
contact us page using and c#

Please make sure to include the following 2 namespaces.
using System;
using System.Net.Mail;

protected void Button1_Click(object sender, EventArgs e)
        if (Page.IsValid)
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("");
            mailMessage.Subject = txtSubject.Text;

            mailMessage.Body = "<b>Sender Name : </b>" + txtName.Text + "<br/>"
                + "<b>Sender Email : </b>" + txtEmail.Text + "<br/>"
                + "<b>Comments : </b>" + txtComments.Text;
            mailMessage.IsBodyHtml = true;

            SmtpClient smtpClient = new SmtpClient("", 587);
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new 
                System.Net.NetworkCredential("", "YourGmailPassowrd");

            Label1.ForeColor = System.Drawing.Color.Blue;
            Label1.Text = "Thank you for contacting us";

            txtName.Enabled = false;
            txtEmail.Enabled = false;
            txtComments.Enabled = false;
            txtSubject.Enabled = false;
            Button1.Enabled = false;
    catch (Exception ex)
        // Log the exception information to 
        // database table or event viewer
        Label1.ForeColor = System.Drawing.Color.Red;
        Label1.Text = "There is an unkwon problem. Please try later";


  1. Hi venkat, I am getting a error like this
    A potentially dangerous Request.Form value was detected from the client (ctl00$ctl00$ContentPlaceHolder1$MainContent$txtComments="these  are t...").

    please help me

  2. Can you please help, I am getting error: there is an unknown problem. Please try later

  3. Your unknown problem is your email. Enter your real gmail name and password.

  4. Thanks!
    Works great! do you have a tutorial on keeping all the form requests on DB?

  5. hi venkat sir ur video is very usefull..but it's work loacaly not on remote server.why...?

  6. I have an errors like (Please enter your valid email) ...

    what is actually problem? many thanks

  7. hello sir I did everything u said but msg came "There is an unkwon problem. Please try later" and in my id msg came like there is someone trying to access in ur account so plz help

    1. hello sir I did everything u said but message came "There is an unknown problem. Please try later" and in my id messageg came like there is someone trying to access in your account Please help

    2. what did you do to solve this problem? is it working locally?


It would be great if you can help share these free resources