Based on the previous post, in your controller you would have to do something like this:
[HttpPost]
public ViewResult Index(Contact_Us model)
{
if (ModelState.IsValid)
{
//I need the Email sender to go here.
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress(model.email));
message.Subject = "New Message from Website";
message.Body = model.message;
SmtpClient client = new SmtpClient();
client.Send(message);
return View("Thanks", Index);
}
else
{
return View();
}
}
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Asp.Net MVC 3 Send Razor contact form to email
Apr 27, 2012 03:01 PM|LINK
Based on the previous post, in your controller you would have to do something like this:
[HttpPost] public ViewResult Index(Contact_Us model) { if (ModelState.IsValid) { //I need the Email sender to go here. MailMessage message = new MailMessage(); message.From = new MailAddress("sender@foo.bar.com"); message.To.Add(new MailAddress(model.email)); message.Subject = "New Message from Website"; message.Body = model.message; SmtpClient client = new SmtpClient(); client.Send(message); return View("Thanks", Index); } else { return View(); } }Blog | Twitter : @Hattan