code for saving contact us details in database

Posted by Parthibansk under ASP.NET on 3/14/2013 | Points: 10 | Views : 1176 | Status : [Member] | Replies : 2
have a contact us form.. wen users submit feedback...values have to stored in database and simultaneously mail..

how to code for the above...




Responses

Posted by: Murugavelmsc on: 3/14/2013 [Member] Starter | Points: 25

Up
0
Down
http://codersbarn.com/post/2008/11/30/ASPNET-Contact-Form.aspx
http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 3/14/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
try this code


protected void Bt_Submit_Click(object sender, EventArgs e)
{

SqlConnection con = new SqlConnection(strConnString);
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into login values(@UserName,@Password,@Email)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@Name", txtName.Text);
com.Parameters.AddWithValue("@Password", txtPassword.Text);
com.Parameters.AddWithValue("@Email", txtEmail.Text);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";


try
{

string toaddress = Email;
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("FromEmailID");
msg.To.Add(new MailAddress(toaddress));
msg.Body = "Hi";
StringBuilder mailbody = new StringBuilder();
msg.Subject = " Your Account Status " ;
mailbody.Append("Dear Sir Body Message");
msg.Body = mailbody.ToString();
msg.IsBodyHtml = true;
System.Net.NetworkCredential credential = new System.Net.NetworkCredential("YourEmailId", "pwd");
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.Credentials = credential;
smtp.Host = "HostName";
smtp.Port = PortNo;
smtp.EnableSsl = false;
smtp.Send(msg);
}
catch (Exception ex)
{
ErrorLog("Error####:" + ex.ToString());
}
}





Mark as Answer if its helpful to you

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response