protected void BtnSubmit_Click(object sender, EventArgs e) { if (Validation()) { try { SqlCommand cmd = new SqlCommand("Insert into Enquiry values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + DropDownList1 .SelectedValue + "','" + TextBox5.Text + "','"+TextBox6.Text +"','"+TxtDegree .Text +"')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Host = "smtp.gmail.com"; client.Port = 587; System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("xyz@gmail.com", "*******"); client.UseDefaultCredentials = false; client.Credentials = credentials; MailMessage msg = new MailMessage(); msg.From = new MailAddress("xyz@gmail.com"); msg.To.Add(new MailAddress("xyz@gmail.com")); msg.Subject = "Enquiry"; msg.IsBodyHtml = true; msg.Body = string.Format("<html><head></head><body>ENQUIRY<BR><hr><br> Name : "+TextBox1 .Text +"<br> Email : "+TextBox2 .Text +"<br> Phone : "+TextBox3 .Text +"<br>Course : "+DropDownList1 .SelectedValue+"<br> Degree :"+TxtDegree .Text +"<br> Message : "+TextBox5 .Text +"</body>"); //msg.Body = string.Format("<html><head></head><body>"+TextBox1 .Text +"</body></html>"); //try //{ client.Send(msg); //lblMsg.Text = "Your message has been successfully sent."; //} //catch (Exception ex) //{ //// lblMsg.ForeColor = Color.Red; //lblMsg.Text = "Error occured while sending your message." + //ex.Message; //} TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox6.Text = ""; DropDownList1.SelectedValue = "0"; TextBox5.Text = ""; TxtDegree.Text = ""; Label1.Text = "Enquiry submitted!"; } catch (Exception ex) { Label1.Text = ex.Message; } } } protected bool Validation() { if (TextBox1.Text.Trim() == "") { Label1.Text = "Enter name!"; TextBox1.Focus(); return false; } if (TextBox2.Text.Trim() == "") { Label1.Text = "Enter email id!"; TextBox2.Focus(); return false; } if (TextBox3.Text.Trim() == "") { Label1.Text = "Enter phone no!"; TextBox3.Focus(); return false; } //if (TextBox4.Text.Trim() == "") //{ // Label1.Text = "Enter course!"; // TextBox4.Focus(); // return false; //} if (TextBox5.Text.Trim() == "") { Label1.Text = "Enter message!"; TextBox5.Focus(); return false; } return true; } protected void LinkButton1_Click(object sender, EventArgs e) { Session.Abandon(); Response.Redirect("Default.aspx"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)