Guest User

Untitled

a guest
Jul 16th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['email'])) {
  3.      
  4.     // EDIT THE 2 LINES BELOW AS REQUIRED
  5.     $email_to = "paul@sztork.com";
  6.     $email_subject = "Contact from SZTORK.com";
  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 you 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.         !isset($_POST['question'])
  25.                                     )
  26.    
  27.                                     {
  28.         died('We are sorry, but there appears to be a problem with the form you submitted.');      
  29.     }
  30.      
  31.     $first_name = $_POST['first_name']; // required
  32.     $last_name = $_POST['last_name']; // required
  33.     $email_from = $_POST['email']; // required
  34.     $telephone = $_POST['telephone']; // not required
  35.     $comments = $_POST['comments']; // required
  36.     $question = $_POST['question']; //required
  37.      
  38.     $error_message = "";
  39.     $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  40.   if(!preg_match($email_exp,$email_from)) {
  41.     $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  42.   }
  43.     $string_exp = "/^[A-Za-z .'-]+$/";
  44.   if(!preg_match($string_exp,$first_name)) {
  45.     $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  46.   }
  47.   if(!preg_match($string_exp,$last_name)) {
  48.     $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  49.   }
  50.   if(strlen($comments) < 2) {
  51.     $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  52.   }
  53.   if(strlen($error_message) > 0) {
  54.     died($error_message);
  55.   }
  56.  
  57.   if (trim($_REQUEST['question']) != '7') {
  58.       $error_message .= 'The is not the next number after 6.<br />';
  59.   }
  60.     $email_message = "Form details below.\n\n";
  61.      
  62.     function clean_string($string) {
  63.       $bad = array("content-type","bcc:","to:","cc:","href");
  64.       return str_replace($bad,"",$string);
  65.     }
  66.      
  67.     $email_message .= "First Name: ".clean_string($first_name)."\n";
  68.     $email_message .= "Last Name: ".clean_string($last_name)."\n";
  69.     $email_message .= "Email: ".clean_string($email_from)."\n";
  70.     $email_message .= "Telephone: ".clean_string($telephone)."\n";
  71.     $email_message .= "Comments: ".clean_string($comments)."\n";
  72.      $email_message .= "Question: ".clean_string($question)."\n";
  73.      
  74. // create email headers
  75. $headers = 'From: '.$email_from."\r\n".
  76. 'Reply-To: '.$email_from."\r\n" .
  77. 'X-Mailer: PHP/' . phpversion();
  78. @mail($email_to, $email_subject, $email_message, $headers);  
  79. header('Location: /')
  80. ?>
  81.  
  82.  
  83.  
  84. <?php
  85. }
  86. ?>
Add Comment
Please, Sign In to add comment