public ActionResult Index(Models.ContactForm contactForm) { //create a connection to the database Models.ContactFormsEntities db = new Models.ContactFormsEntities(); //add our contact info to the database. db.ContactForms.Add(contactForm); //save the changes db.SaveChanges(); //kickk the user to the thankyou page return(RedirectToAction("ThankYou", "Contact")); }
public ActionResult Contact(Models.ContactForm contactForm) { //add the form to the database try { //try doing something... //set the date created contactForm.DateCreated = DateTime.Now; //adding something to the database... //step 1: create the data context Models.ContactFormsEntities db = new Models.ContactFormsEntities(); //step 2: add the object to the table db.ContactForms.Add(contactForm); //step 3: SAVE db.SaveChanges(); } catch (Exception ex) { //if it blows up do this... ViewBag.Error = ex.Message; return(View("Error")); } //mail us a copy //SMTP: Simple Mail Transfer Protocol //host: mail.dustinkraft.com //port: 587 //user: [email protected] //password: techIsFun1 MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**"); //mail.From = new MailAddress("*****@*****.**"); //mail.To.Add("*****@*****.**"); mail.Subject = "AWESOME EMAIL FROM " + contactForm.Name; mail.Body = string.Format("{0} at {1} just sent you the following message: {2}", contactForm.Name, contactForm.Email, contactForm.Body); //connecting to actual email server SmtpClient client = new SmtpClient("mail.dustinkraft.com"); //client.Host = "mail.dustinkraft.com"; client.Port = 587; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "techIsFun1"); client.Send(mail); //redirect user to the Thank You page return(RedirectToAction("ThankYou", "Home")); }