0

I had created the bootstrap contact form in a website. can anyone help me to write the code for mail function in C#,That yje user fill the form ,when the user clicks submit button,the details must sent to admin's mail.

Here is the code for bootstrap form:

<form class="form form-container"> <span class="col-xs-12 col-md-6"> <label for="Name">Name <span class="red">*</span></label> <input class="form-control" name="name" type="text" required> </span> <span class="col-xs-12 col-md-6"> <label for="Company">Company</label> <input class="form-control" name="company" type="text" > </span> <span class="col-xs-12 col-md-4"> <br> <label for="Gender">Gender <span class="red">*</span></label> <select class="form-control" name="gender" required> <option value="">Select option</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> </span> <span class="col-xs-12 col-md-4"> <br> <label for="Email">E-Mail <span class="red">*</span></label> <input type="email" name="email" class="form-control" required> </span> <span class="col-xs-12 col-md-4"> <br> <label for="Phone">Phone <span class="red">*</span></label> <input type="text" name="phone" class="form-control" required> </span> <span class="col-xs-12 col-md-12"> <br> <label for="Subject">Subject <span class="red">*</span></label> <input type="text" name="subject" class="form-control" required> </span> <span class="col-xs-12 col-md-12"> <br> <label for="Message">Message <span class="red">*</span></label> <textarea class="form-control" rows="6" name="message" required></textarea> <br> </span> <span class="col-xs-12"> <input type="submit" class="btn btn-md btn-success" value="Send message"><br><br><br><br> </span> </form> 
1

1 Answer 1

0

You have to use Smtpclient to send the email from your code behind action Example is at How to send email in ASP.NET C#

Sample code is

try { MailMessage mailMessage = new MailMessage(); mailMessage.To.Add("[email protected]"); mailMessage.From = new MailAddress("[email protected]"); mailMessage.Subject = "ASP.NET e-mail test"; mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!"; SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com"); smtpClient.Send(mailMessage); Response.Write("E-mail sent!"); } catch(Exception ex) { Response.Write("Could not send the e-mail - error: " + ex.Message); } 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, i have no idea in c#, I have a knowledge in php. Could you tell me what are the steps to do after written the code for form.
Better to follow some basic C# tutorial prior. Also i will suggests you to follow asp.net tutorial as well
thanks for your info

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.