Contact Us Form in PHP – Info PHP

Introduction

 

In this article I show how to create a “ Us” in PHP. This form is very simple and anyone can use this to help understand PHP. You can edit and add fields. You will first create a HTML file for the Contact Us form design. In the form field you will set the action for your PHP file.

 

Example 

 

This is your HTML file:

  1. html>  
  2. head>  
  3. title>Contact Formtitle>  
  4. head>  
  5. body bgcolor=“#CED2B9”>  
  6. table width=“400” border=“0” align=“center” cellpadding=“3” cellspacing=“1”>  
  7. tr>  
  8. td>strong>Contact Formstrong>td>  
  9. tr>  
  10. table>  
  11. table width=“400” border=“0” align=“center” cellpadding=“0” cellspacing=“1”>  
  12. tr>  
  13. td>  
  14. form name=“form1” method=“post” action=“send.php”>  
  15. table width=“100%” border=“0” cellspacing=“1” cellpadding=“3”>  
  16. tr>  
  17. td>Emailtd>  
  18. td>:td>  
  19. td>  
  20. input name=“email” type=“text” id=“customer_mail” size=“20”>  
  21. td>  
  22. tr>  
  23. tr>  
  24. td>Nametd>  
  25. td>:td>  
  26. td>  
  27. input name=“name” type=“text” id=“name” size=“20”>  
  28. td>  
  29. tr>  
  30. tr>  
  31. td width=“16%”>Subjecttd>  
  32. td width=“2%”>:td>  
  33. td width=“82%”>  
  34. input name=“sub” type=“text” id=“subject” size=“24”>  
  35. td>  
  36. tr>  
  37. tr>  
  38. td>Detailtd>  
  39. td>:td>  
  40. td>  
  41. textarea name=“msg” cols=“20” rows=“4” id=“detail”>textarea>  
  42. td>  
  43. tr>  
  44. tr>  
  45. td> td>  
  46. td> td>  
  47. td>  
  48. input type=“submit” name=“Submit” value=“Submit”>  
  49. input type=“reset” name=“Submit2” value=“Reset”>  
  50. td>  
  51. tr>  
  52. table>  
  53. form>  
  54. td>  
  55. tr>  
  56. table>  
  57. body>  
  58. html>  

In the PHP file I use the mail() function to send the contact information but this function does not work for the local host. You can see that I have described below how to sendi the contact. I will create a PHP file for data submission.

  1. $subject = $_POST[‘sub’];  
  2. $name = $_POST[‘name’];  
  3. $from = $_POST[’email’];  
  4. $detail = $_POST[‘msg’];  
  5. $subject =“$subject”;  
  6. $message=“$detail”;  
  7. $mail_from=“$from”;  
  8. $header=;  
  9. $to =‘studentvinod.87@gmail.com’;  
  10.   
  11. if($name != “”$from != “”$subject != “”$message != “”)  
  12. {  
  13. mail($to,$subject,$message,$header);  
  14. }  
  15. else   
  16. {   
  17. echo “Please fill in all fields and submit again!”;   
  18. }  
  19. ?>  

 

When you submit a blank field, this error is generated:

 

image 3.jpg
image2.jpg

 

Article Prepared by Ollala Corp

You might also like
Leave A Reply

Your email address will not be published.