I am sending email upon form submit. How can i include the form content in the email body section?

I am saving form content into mydb with db.Employee.Add(employee); I specify my email text with string text.

Below you can see the code and my form.

namespace MvcApplication8.Controllers
public class PTFController : Controller
    private UsersContext db = new UsersContext();

    public ActionResult Create(Employee employee)
        if (ModelState.IsValid)

            string Text = "<html> <head> </head>" +
    " <body style= \" font-size:12px; font-family: Arial\">" +
    ????? +

            SendEmail("receiver@somemail.com", Text);

            return RedirectToAction("Index");

        return View(employee);

    public static bool SendEmail(string SentTo, string Text)
        MailMessage msg = new MailMessage();

        msg.From = new MailAddress("noreply@myemail.com");
        msg.Subject = "New email";
        msg.Body = Text;
        msg.IsBodyHtml = true;

        SmtpClient client = new SmtpClient("mysmtp.address.com", 25);

        client.UseDefaultCredentials = false;
        client.EnableSsl = false;
        client.Credentials = new NetworkCredential("mywindowsusername", "mypassword");
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        //client.EnableSsl = true;

        catch (Exception)
            return false;
        return true;

this is the form:


    @using (Html.BeginForm()) {


    <div class="editor-label">
        @Html.LabelFor(model => model.EmployeeName)
    <div class="editor-field">
        @Html.EditorFor(model => model.EmployeeName)
        @Html.ValidationMessageFor(model => model.EmployeeName)

    <div class="editor-label">
        @Html.LabelFor(model => model.DepartmentID)
    <div class="editor-field">
        @Html.EditorFor(model => model.DepartmentID)
        @Html.ValidationMessageFor(model => model.DepartmentID)

Related posts

Recent Viewed