Friday 15 April 2011

ASP.NET Contact Form - output to email and access database -


I'm new to ASP.NET, and I'm trying to create a contact form that, along with the submission Sends an email on storage to data in a database.

I have read many tutorials, and I am quite comfortable with a basic contact form for email setup - but I am having trouble in its database part.

Please tell me if you have ever done this, or if you can provide any information that would help me with this work.

I am running ASP.NET 2.0

Thanks to C # and I am very new to ASP.NET (first year IT student).

Here is the code for ASPX. Attached in CSI file form:

  using the system; Using System.Collections.Generic; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Net.Mail; Using System.Data; Using System.Data.SqlClient; Using System.configuration; Public Partial Classroom Contact: System.Web.UI.Page {Secure Zero Page_load (Object Sender, EventArgE) {} Reset event code (will reset form data): Protected Zero Reset (Objects, EventAgds E) {Fname. Text = ""; Lname.Text = ""; E-mail. Text = ""; phone. Text = ""; Comments.Text = ""; } // Code for SendMail event; The email will be sent and the information will be sent to the database in the email: Protected Zero SendMail (Object Sender, EventArgs e) {MailMessage mail = new MailMessage (); similarity. From = new mailaddress (email. Text); Mail.To.Add ("The email address where you sent the message"); Mail.Subject = "Contact Us"; Mail.IsBodyHtml = True; Mail.Body + = "First name:" + fname.Text + "
" similarity. Body + = "Last name:" + lname.Text + "
"; Mail.Body + = "Comments:" + comments.Text + "

"; Mail.Body + = "Phone Number:" + Phone Text + "& lt; br / & gt;"; SmtpClient smtp = new SmtpClient (); Smtp.Host = "SMTP Relay Server Name"; Smtp.Send (mail); } Secure Data Interfo (Object Sender, EventAgps E) {SQL Connection iConnection = New SQL Connection (Configuration Manager Connection Connection ["WEB.CONFIG CONNECTION STRING NAME"]. ToString ()); System.Data.SqlClient.SqlCommand CMD = New System.Data. SQLLient.SqlCommand (); Cmd.CommandType = System.Data.CommandType.Text; Cmd.CommandText = "Include table name (fan, lin, email, phone, comment) in prices (@funam, @ name, @mail, @ phone, @comments)"; Cmd.Connection = myConnection; Cmd.Parameters.Add ("@ fname", fname.Text); Cmd.Parameters.Add ("@ lname", lname.Text); Cmd.Parameters.Add ("@ Email", Email Text); Cmd.Parameters.Add ("@phone", phone. Text); Cmd.Parameters.Add ("@ Comments", comments. Text); MyConnection.Open (); Cmd.ExecuteNonQuery (); MyConnection.Close (); }}

No comments:

Post a Comment