Prasad Bhagat

Prasad Bhagat

  • NA
  • 516
  • 237.3k

How to implement contactus form in html?

Apr 16 2016 12:13 PM
Dear All,
 
iam looking for create a page in hml for contact us ..
 
 
after designing i dont know how to write a script for send mail to mail id .please help
 
 

Answers (5)

0
Rahul Chavan

Rahul Chavan

  • 0
  • 912
  • 138.4k
Apr 16 2016 10:06 PM
Prasad
 
Pure html code will not allow you to send email.
You need SMTP for sending email or you need to embed php in javascript(it is not a good practice).
You can call server method on your form action. 
0
Prasad Bhagat

Prasad Bhagat

  • 0
  • 516
  • 237.3k
Apr 16 2016 1:58 PM
Hi Manas, Not Exactly AM just implementing with .html page only.. i have html controles and now i click the submit button then i want to send it to mail .
0
Manas Mohapatra

Manas Mohapatra

  • 89
  • 20.4k
  • 16.7m
Apr 16 2016 1:48 PM
Then you can use AJAX.
 
If you are using jQuery then use $.ajax().
 
Conversely if you are using only Javascript then you can implement XMLHttpRequest object. Follow below link:
 
http://www.c-sharpcorner.com/UploadFile/manas1/implementing-ajax-concept-in-Asp-Net-using-xmlhttprequest/ 
 
 
0
Prasad Bhagat

Prasad Bhagat

  • 0
  • 516
  • 237.3k
Apr 16 2016 1:39 PM
Dear Manas , am Asking for html with java script .
0
Manas Mohapatra

Manas Mohapatra

  • 89
  • 20.4k
  • 16.7m
Apr 16 2016 1:19 PM
First design your "contact us" page. Follow below links:
 
http://www.webdesignerdepot.com/2013/03/20-excellent-contact-pages/ 
 
http://www.awwwards.com/25-impressive-contact-forms.html
 
Follow below link how it is implemented in ASP.NET
 
http://www.codersbarn.com/post/2008/11/30/ASPNET-Contact-Form.aspx
 
If you want to make ContactUs page as *.html , *.aspx then you need to follow below steps. 
 
Add following code in HTML page: 
  1. <form method="post" action="contactus.aspx">  
  2.    Email: <input type="text" name="toEmail" /><br />   
  3.    Subject: <textarea name="message"></textarea><br />  
  4.    <input type="button" text="Send" />   
  5. </form>  
Next in  code behind page contactus.aspx.cs, add below code:
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.     if (Request.Form.Count > 0)  
  4.     {  
  5.         string formEmail = "";  
  6.         string fromEmail = "from@email.com";  
  7.         string defaultEmail = "default@email.com";  
  8.         string sendTo1 = Request.Form.Keys["toEmail"];  
  9.   
  10.         int x = 0;  
  11.           
  12.         System.Net.Mail.MailMessage myMsg = new System.Net.Mail.MailMessage();  
  13.         SmtpClient smtpClient = new SmtpClient();  
  14.   
  15.         try  
  16.         {  
  17.             myMsg.To.Add(new System.Net.Mail.MailAddress(defaultEmail));  
  18.             myMsg.IsBodyHtml = true;  
  19.             myMsg.Body = formEmail;  
  20.             myMsg.From = new System.Net.Mail.MailAddress(fromEmail);  
  21.             myMsg.Subject = "Sent using Gmail Smtp";  
  22.             smtpClient.Host = "smtp.gmail.com";  
  23.             smtpClient.Port = 587;  
  24.             smtpClient.EnableSsl = true;  
  25.             smtpClient.UseDefaultCredentials = true;  
  26.             smtpClient.Credentials = new System.Net.NetworkCredential("testing@gmail.com""pward");  
  27.   
  28.             smtpClient.Send(defaultEmail, sendTo1, "Sent using gmail smpt", formEmail);  
  29.   
  30.         }  
  31.         catch (Exception ee)  
  32.         {  
  33.             debug.Text += ee.Message;  
  34.         }  
  35.     }  
  36. }