asp.net mvc 4 Send form from site to email -


i have feedback form on mvc site, looks like

enter image description here

and need send form email.

i created model form

 using system;  using system.collections.generic;  using system.linq;  using system.web;   namespace componenttrading.web.models  { public class feedbackform     {     public string name { get; set; }      public string email { get; set; }      public string phone { get; set; }     public string message { get; set; }     } } 

i created view form contacts.cshtml

 @using (html.beginform("contacts", "home", formmethod.post, new { id = "contact-form" })) { <fieldset>     @html.textboxfor(model => model.name, new { @value = name })     @html.textboxfor(model => model.email, new { @value = "e-mail" })     @html.textboxfor(model => model.phone, new { @value = phone })     @html.textareafor(model => model.message, new { @class = "img-shadow" })     <input class="form-button" data-type="reset" value="clear" />     <input class="form-button" data-type="submit" type="submit" value="send" /> </fieldset>      } 

and wrote code @ controller

    [httpget]     public actionresult contacts()     {         feedbackform temp = new feedbackform();         temp.message = @resources.global.contacts_form_message_field;         return view(temp);     }       [httppost]     public actionresult contacts(feedbackform model)     {         string text = "<html> <head> </head>" +         " <body style= \" font-size:12px; font-family: arial\">"+         model.message+         "</body></html>";          sendemail("tayna-anita@mail.ru", text);         feedbackform tempform = new feedbackform();         return view(tempform);     }       public static bool sendemail(string sentto, string text)     {         mailmessage msg = new mailmessage();          msg.from = new mailaddress("test@mail.ru");         msg.to.add(sentto);         msg.subject = "password";         msg.body = text;         msg.priority = mailpriority.high;         msg.isbodyhtml = true;          smtpclient client = new smtpclient("smtp.mail.ru", 25);            client.usedefaultcredentials = false;         client.enablessl = false;         client.credentials = new networkcredential("testlogin", "testpassword");         client.deliverymethod = smtpdeliverymethod.network;         //client.enablessl = true;          try         {             client.send(msg);         }         catch (exception)         {             return false;         }         return true;     } 

i dont have errors @ code, when push send button, dont email , form doesnt become clear.

i used fiddler web debugger , got send-button click enter image description here

as see, means right, cant undersnand what's wrong?

i have copy-pasted code , got work, small modifications:

  1. i did not set credentials property
  2. i modified template remove @value attribute:

    @html.textboxfor(model => model.name) @html.textboxfor(model => model.email) @html.textboxfor(model => model.phone)

these changes made , got application work. leads me believe there must wrong in smtp client's configuration. can examine exception thrown client.send(msg);? expect invalid network credentials or that.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -