Saturday, September 26, 2015

Contact us page using asp.net and c# continued

Suggested Videos
Part 139 - How to upload and download files using asp.net and c#
Part 140 - Creating an image gallery using asp.net and c#
Part 141 - Contact us page using asp.net 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 asp.net and c#



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

contactus.aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        if (Page.IsValid)
        {
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress("YourGmailID@gmail.com");
            mailMessage.To.Add("AdministratorID@YourCompany.com");
            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("smtp.gmail.com", 587);
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new 
                System.Net.NetworkCredential("YourGmailID@gmail.com", "YourGmailPassowrd");
            smtpClient.Send(mailMessage);

            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";
    }
}


If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website