1. <?php
  2. /*
  3. *
  4. * edit three lines below
  5. *
  6. */
  7.  
  8. $your_name = "Your Name";
  9. $your_email = "youremail@domain.com";
  10. $your_web_site_name = "Your Web Site Name";
  11.  
  12. ?>
  13.  
  14. <?php
  15. //If the form is submitted
  16. if(isset($_POST['name'])) {
  17.  
  18. //variables
  19. $errorMessage = "";
  20.  
  21. //Check to make sure that the name field is not empty
  22. if(trim($_POST['name']) === '') {
  23. $hasError = true;
  24. } else {
  25. $name = trim($_POST['name']);
  26. }
  27.  
  28. //Check to make sure sure that a valid email address is submitted
  29. if(trim($_POST['email']) === '') {
  30. $hasError = true;
  31. } else if (!preg_match('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$^', trim($_POST['email']))) {
  32. $hasError = true;
  33. $errorMessage = "Please enter a valid email address!";
  34. } else {
  35. $email = trim($_POST['email']);
  36. }
  37.  
  38. //phone
  39. if(isset($_POST['phone'])) $phone = trim($_POST['phone']);
  40.  
  41. //company name
  42. if(isset($_POST['company_name'])) $company_name = trim($_POST['company_name']);
  43.  
  44. //company url
  45. if(isset($_POST['company_url'])) $company_url = trim($_POST['company_url']);
  46.  
  47.  
  48. //Check to make sure comments were entered
  49. if(trim($_POST['message']) === '') {
  50. $hasError = true;
  51. } else {
  52. if(function_exists('stripslashes')) {
  53. $comments = stripslashes(trim($_POST['message']));
  54. } else {
  55. $comments = trim($_POST['message']);
  56. }
  57. }
  58.  
  59.  
  60.  
  61. //If there is no error, send the email
  62. if(!isset($hasError)) {
  63.  
  64. $emailTo = $your_email;
  65. $subject = 'Contact Form Submission from '.$name;
  66.  
  67. //message body
  68. $body ="Name: $name \n\n";
  69. $body .="Email: $email \n\n";
  70. if(isset($phone)) $body .="Phone:$phone\n\n";
  71. if(isset($company_name)) $body .="Company Name:$company_name\n\n";
  72. if(isset($company_url)) $body .="Company Url:$company_url \n\n";
  73. $body .="Message: $comments";
  74.  
  75.  
  76. $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n";
  77. $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
  78.  
  79. mail($emailTo, $subject, $body, $headers);
  80.  
  81. $emailSent = true;
  82. }
  83. }
  84. ?>
  85.  
  86. <?php if(isset($emailSent) == true) { ?>
  87. <div class="ok_box">
  88. <h3>Thanks, <?php echo $name;?></h3>
  89. <p>Your email was successfully sent. We will be in touch soon.</p>
  90. </div>
  91. <?php } ?>
  92.  
  93. <?php if(isset($hasError) ) { ?>
  94. <div class="error_box">
  95. There was an error submitting the form.
  96. <br />
  97. <?php echo $errorMessage;?>
  98. </div>
  99. <?php } ?>