Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 7th, 2012  |  syntax: None  |  size: 2.51 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. if(isset($_POST['email'])) {
  3.        
  4.         // EDIT THE 2 LINES BELOW AS REQUIRED
  5.         $email_to = "sales@**secret**";
  6.         $email_subject = "**secret**Sales Inquiry";
  7.        
  8.        
  9.         function died($error) {
  10.                 // your error code can go here
  11.                 echo "We are very sorry, but there were error(s) found with the form your submitted. ";
  12.                 echo "These errors appear below.<br /><br />";
  13.                 echo $error."<br /><br />";
  14.                 echo "Please go back and fix these errors.<br /><br />";
  15.                 die();
  16.         }
  17.        
  18.         // validation expected data exists
  19.         if(!isset($_POST['first_name']) ||
  20.                 !isset($_POST['last_name']) ||
  21.                 !isset($_POST['email']) ||
  22.                 !isset($_POST['telephone']) ||
  23.                 !isset($_POST['comments'])) {
  24.                 died('We are sorry, but there appears to be a problem with the form your submitted.');         
  25.         }
  26.        
  27.         $first_name = $_POST['first_name']; // required
  28.         $last_name = $_POST['last_name']; // required
  29.         $email_from = $_POST['email']; // required
  30.         $telephone = $_POST['telephone']; // not required
  31.         $comments = $_POST['comments']; // required
  32.        
  33.         $error_message = "";
  34.         $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  35.   if(!eregi($email_exp,$email_from)) {
  36.         $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  37.   }
  38.         $string_exp = "^[a-z .'-]+$";
  39.   if(!eregi($string_exp,$first_name)) {
  40.         $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  41.   }
  42.   if(!eregi($string_exp,$last_name)) {
  43.         $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  44.   }
  45.   if(strlen($comments) < 2) {
  46.         $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  47.   }
  48.   if(strlen($error_message) > 0) {
  49.         died($error_message);
  50.   }
  51.         $email_message = "Form details below.\n\n";
  52.        
  53.         function clean_string($string) {
  54.           $bad = array("content-type","bcc:","to:","cc:","href");
  55.           return str_replace($bad,"",$string);
  56.         }
  57.        
  58.         $email_message .= "First Name: ".clean_string($first_name)."\n";
  59.         $email_message .= "Last Name: ".clean_string($last_name)."\n";
  60.         $email_message .= "Email: ".clean_string($email_from)."\n";
  61.         $email_message .= "Telephone: ".clean_string($telephone)."\n";
  62.         $email_message .= "Comments: ".clean_string($comments)."\n";
  63.        
  64.        
  65. // create email headers
  66. $headers = 'From: '.$email_from."\r\n".
  67. 'Reply-To: '.$email_from."\r\n" .
  68. 'X-Mailer: PHP/' . phpversion();
  69. @mail($email_to, $email_subject, $email_message, $headers);  
  70. ?>
  71.  
  72. <!-- include your own success html here -->
  73.  
  74. Thank you for contacting us. We will be in touch with you very soon.
  75.  
  76. <?
  77. }
  78. ?>