Posted by : Anwar Hossain
Category : Mail sending in asp.net c#

Feedback form example in ASP.Net C#

Dear viewer’s I will show how to create simple feedback from in ASP.Net C #. For implementing Email sending we have to need to import System.Net.Mail namespace in our page codebehind part .Now we will use two classes one is MailMessage and another is SmtpClient. MailMessage class is used for adding content of the mail such as name,subjct,email, and body content. SmtpClient is used for sending mail using through SMTP server.

Feedback form example in ASP.Net C#

HTML

<html >

<head runat="server">

    <title></title>

    <style type="text/css">

        .style1

        {

            color: #FF3300;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <fieldset style="width: 40%;">

            <legend>Feedback</legend>

            <table cellpadding="2" cellspacing="5" >

               

                <tr>

                    <td width="80px">

                    </td>

                    <td>

                    </td>

                </tr>

                <tr>

                    <td width="80px">

                        Name<span style="color: #CC3300"> *</span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtName" runat="server" Width="200px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

                            ErrorMessage="Name Required" ForeColor="#FF3300"

                            ControlToValidate="txtName"></asp:RequiredFieldValidator>

                    </td>

                </tr>

                <tr>

                    <td>

                        Subject <span class="style1">*</span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtSubject" runat="server" Width="200px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"

                            ErrorMessage="Subject Required" ForeColor="#FF3300"

                            ControlToValidate="txtSubject"></asp:RequiredFieldValidator>

                    </td>

                </tr>

                <tr>

                    <td>

                        E-mail<span style="color: #CC3300"> *</span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtEmail" runat="server" Width="300px"></asp:TextBox>

                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"

                            ErrorMessage="Email Required" ForeColor="#FF3300"

                            ControlToValidate="txtEmail"></asp:RequiredFieldValidator>

                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"

                            ErrorMessage="Not a vailed email" ControlToValidate="txtEmail"

                            ForeColor="#FF3300"

                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

                    </td>

                </tr>

                <tr>

                    <td>

                        Inquiry<span style="color: #CC3300"> </span>

                    </td>

                    <td>

                        <asp:TextBox ID="txtInquiry" runat="server" Height="100px" TextMode="MultiLine" Width="400px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                    <td>

                        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                    <td>

                        <asp:Button ID="btnSubmit" runat="server" Text="Send" Width="100px" OnClick="btnSubmit_Click1" />

                    </td>

                </tr>

                <tr>

                    <td>

                        &nbsp;

                    </td>

                    <td>

                        &nbsp;

                    </td>

                </tr>

            </table>

        </fieldset>

    </div>

    </form>

</body>

</html>

CODE BEHIND

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Net.Mail;

using System.Net;

using System.Drawing;

using System.IO;

 

public partial class Feedback : System.Web.UI.Page

{

   

  

    private void EmailFeedback()

    {

 

        //create the mail message

        MailMessage mail = new MailMessage();

 

        //set the addresses

        mail.From = new MailAddress(txtEmail.Text.Trim());

 

        mail.To.Add("anwar@csharpexample.com");

 

        //set the content

        mail.Subject = "Enquiry Form";

 

        //Body to be displayed

        mail.Body = "<h2>" + "Enquiry from " + " " + txtName.Text + "</h2>" + "<br><br>" +

                "Subject: " + txtSubject.Text + "<br>" +        

                "Email : " + txtEmail.Text.Trim() + "<br>" +

                "InQuiry: " + txtInquiry.Text.Trim() + "<br>" +             

                "Thank You";

 

        mail.IsBodyHtml = true;

 

        // smtp settings

        SmtpClient smtp = new SmtpClient("mail.csharpexample.com");

        NetworkCredential SMTPUserInfo = new NetworkCredential("anwar@csharpexample.com", "Aic12234@");

        smtp.Credentials = SMTPUserInfo;

        smtp.Send(mail);

 

       

      

 

    }

 

    private void Clear()

    {

        txtName.Text = string.Empty;

        txtSubject.Text = string.Empty;    

        txtEmail.Text = string.Empty;  

        txtInquiry.Text = string.Empty;

 

    }

     

    protected void btnSubmit_Click1(object sender, EventArgs e)

    {

      

            EmailFeedback();

            lblMsg.ForeColor = Color.Green;

            Clear();

            lblMsg.Text = "Thank You for Your Inquiry";

 

       

    }

}

 

Out Put

Feedback-in-ASP-CSharp



Realted Article Headline

Send mail with multiple selections in ASP.Net C #.
Feedback form with Yes or No Option in ASP.Net C#
Send mail with attachment file in ASP.Net C #
Send mail using Gmail account in ASP.Net C#.
Feedback form example in ASP.Net C#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection