Asp.net contact form not submitting value properly RRS feed

  • Question

  • User-1173300311 posted

    My website have contact form where customer fill their details for that I use domain email to send filled details to my inbox. Form working good but the issue is when details come to my inbox its look like: Name - 5a313471b73da, mobile No.'blank' etc.

    And one more thing it is working for my country, all details come to my inbox as it but when submit from other country then this issue is coming...

    here is my code...

                  //Gmail Address from where you send the mail
                    var fromAddress = System.Configuration.ConfigurationManager.AppSettings["FromEmailId"].ToString();
                    // any address where the email will be sending
                    var toAddress = "email";
                    //Password of your gmail address
                    string fromPassword = System.Configuration.ConfigurationManager.AppSettings["FromPwd"].ToString();
                    // Passing the values and make a email formate to display
                    string subject = "Enquiry";
                    // smtp settings
                    MailMessage Msg = new MailMessage();
                    MailAddress fromMail = new MailAddress(fromAddress);
                    // Sender e-mail address.
                    Msg.From = fromMail;
                    // Recipient e-mail address.
                    Msg.To.Add(new MailAddress("email"));
                    // Subject of e-mail
                    Msg.Subject = "Enquiry";
                    string body = "Name - " + name.Text.ToString() + "\n";
                    body += "Email Id -" + emailId.Text.ToString() + "\n";
                    body += "Contact No -" + Phone.Text.ToString() + "\n";
                    body += "Subject -" + Subject.Text.ToString() + "\n";
                    body += "Message -" + message.Text.ToString() + "\n";
                    Msg.IsBodyHtml = true;
                    var smtp = new System.Net.Mail.SmtpClient();
                        smtp.Host = "smtpout.secureserver.net";
                        smtp.Port = 3535;                   
                        smtp.EnableSsl = false;
                        // smtp.UseDefaultCredentials = false;
                        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                        smtp.Timeout = 200000;
                    smtp.Send(fromAddress, toAddress, subject, body);
    Saturday, December 16, 2017 6:53 AM

All replies

  • User753101303 posted


    I don't see anything related to the country in your code. So I can't imagine why you see a difference depending on which country is selected (not 100% sure which differences).

    Also it is confusing that you create a MailMessage while finally not using it for the final "Send". Do you have changed something to try fixing your issue? For example if you try to send an HTML message body, multiple spaces are collapsed to a single space and newline is ignored (which is for now my understanding about what you see).

    Start first by making sure if you want to use HTML or plain text messages. Also see maybe https://docs.microsoft.com/en-us/visualstudio/debugger/ to inspect how your app runs and possibly spot the issue.

    This is really the entire code? For now it seems to me you are sending sometimes an HTML message and sometimes a plain text message ???

    Saturday, December 16, 2017 8:30 AM
  • User-1173300311 posted


    Thanks for your suggestion.

    There is no selection of country just i want to say when website open in other country and submit contact form.

    Saturday, December 16, 2017 9:08 AM
  • User61956409 posted

    Hi ajyaul96@gmail.com,


    string body = "Name - " + name.Text.ToString() + "\n"; body += "Email Id -" + emailId.Text.ToString() + "\n"; body += "Contact No -" + Phone.Text.ToString() + "\n"; body += "Subject -" + Subject.Text.ToString() + "\n"; body += "Message -" + message.Text.ToString() + "\n";

    According to your code, you retrieve the values of TextBoxes (name, emailId and Phone etc) and set the message body with these input values. If the format of these input values are not always as your expected, please check if you do validation to check user inputs. If you do not check the information that user enters are valid before submit the form, the email receiver might receive non meaningful data, like Name - 5a313471b73da. To avoid it, you can do client validation to check user inputs before user submit the form.

    <o:p></o:p>With Regards, <o:p></o:p>

    Fei Han<o:p></o:p>

    Tuesday, December 19, 2017 2:09 AM
  • User-1173300311 posted

    hi Fie Han,

    Yes, I have use client side validation for email and Phone but not working. 

    Its working for India but when client open web site in other country then this problem come.

    Tuesday, December 19, 2017 4:22 AM
  • User753101303 posted

    So your web site uses the browser preferred language ? I'm trying to understand the EXACT issue and how it could be related to the "current" country (and you always have the problem for other countries or it happens just sometimes ?)

    First as your code uses both a MailMessage object but finally sends directly the text without using the MailMessage it is unclear if you want to send an HTML or a plain text message. Which format do you want ?

    For now my understanding is that newlines are not showing up in the mail (which is expected for HTML which uses <br> rather than newline).

    Or if you meant you have no data at all, could it be because validation is done using JavaScript and so doesn't happen if JavaScript is disabled? If yes, does it happen again if you add a server side validation ?

    Tuesday, December 19, 2017 8:08 AM