title: contact page form throws error MVC
body: <p>I've been banging my head trying to figure out what's wrong here. I'm new to c# and fairly new to MVC in general. I need a small, simple email contact form for my website. I'm not exactly sure what the rhyme or reason is, but the controller will register all the fields for the form, but skips <code>smtp.Send(msg);</code> and jumps right to the catch method. I tried adding a <code>[GET]</code> method after the <code>[POST]</code> which I've read helps, but still no luck. I have a feeling it is a problem with the smtp ports or host, but I can't find any documentation. </p>
  
  <p>Also, I tried adding some snippets for button functionality too, but no luck either. Any help would be great. </p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class ContactModels
  {
      [Required(ErrorMessage ="Your name is required")]
      public string FullName { get; set; }
  
      [Required(ErrorMessage = "Your email is required")]
      public string Email { get; set; }
  
      [Required(ErrorMessage = "Your phone number is required")]
      public string Phone { get; set; }
  
      [Required(ErrorMessage = "You must type a message")]
      public string Comment { get; set; }
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>    &lt;div class="col-md-4"&gt;
      &lt;p&gt;&lt;strong&gt;Phone: &lt;/strong&gt;586.xxx.xxxx&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Email: &lt;/strong&gt;&lt;a href="mailto:Tom@blank.com"&gt;example@example.com&lt;/a&gt;&lt;/p&gt;
      &lt;p&gt;&lt;strong&gt;Address: &lt;/strong&gt;Address Here&lt;/p&gt;
  
      &lt;h3&gt;Connect with us through Email &lt;/h3&gt;
  
      @using (Html.BeginForm(FormMethod.Post))
      {
          @Html.ValidationSummary(true)
  
      &lt;div class="row"&gt;
          @Html.LabelFor(model=&gt;model.FullName, "Name: ")
          @Html.EditorFor(model=&gt;model.FullName)
          @Html.ValidationMessageFor(model=&gt;model.FullName)
      &lt;/div&gt;
      &lt;div class="row"&gt;
          @Html.LabelFor(model=&gt;model.Email, "Email: ")
          @Html.EditorFor(model=&gt;model.Email)
          @Html.ValidationMessageFor(model=&gt;model.Email)
      &lt;/div&gt;
      &lt;div class="row"&gt;
          @Html.LabelFor(model=&gt;model.Phone, "Phone: ")
          @Html.EditorFor(model=&gt;model.Phone)
          @Html.ValidationMessageFor(model=&gt;model.Phone)
      &lt;/div&gt;
      &lt;div class="row"&gt;
          @Html.LabelFor(model=&gt;model.Comment, "Message: ")
          @Html.TextAreaFor(model=&gt;model.Comment)
          @Html.ValidationMessageFor(model=&gt;model.Comment)
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;input type="submit" value="Send"/&gt;
          &lt;input type="reset" value="Reset"/&gt;
      &lt;/div&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>    public ActionResult Contact()
      {
          return View();
      }
  
      [HttpPost]
      public ActionResult Contact(Models.ContactModels c)
      {
          if (ModelState.IsValid)
          {
              try
              {
                  MailMessage msg = new MailMessage();
                  SmtpClient smtp = new SmtpClient();
                  MailAddress from = new MailAddress(c.Email.ToString());
                  StringBuilder sb = new StringBuilder();
  
                  msg.To.Add("myEmailHere@gmail.com");
                  msg.Subject = "Contact Us";
                  msg.IsBodyHtml = false;
                  smtp.Host = "smtp.gmail.com";
  
                  smtp.Port = 993;
  
                  sb.Append("Name: " + c.FullName);
                  sb.Append(Environment.NewLine);
  
                  sb.Append("Email: " + c.Email);
                  sb.Append(Environment.NewLine);
  
                  sb.Append("Phone: " + c.Phone);
                  sb.Append(Environment.NewLine);
  
                  sb.Append("Comment: " + c.Comment);
                  sb.Append(Environment.NewLine);
  
                  msg.Body = sb.ToString();
                  smtp.Send(msg);
                  msg.Dispose();
  
                  return View("Success");
              }
              catch(Exception)
              {
                  return View("Error");
              }
          }
  
          return View();
      }
  </code></pre>