dutchy1001

Untitled

Jul 23rd, 2018
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if(isset($_POST['email']))
  4.   {
  5.     // Here is the email to and from - information
  6.     $email_to = "your e-mail@here.com";
  7.     $email_subject = "info";
  8.     $email_from = "info";
  9.  
  10.     // Variables
  11.     $name = $_POST['name'];
  12.     $email = $_POST['email'];
  13.     $phone = $_POST['phone'];
  14.     $msg = $_POST['msg'];
  15.  
  16.     //*** Functions start ***/
  17.  
  18.     // Error Code
  19.     function died($error)
  20.       {
  21.         echo "We are sorry, but there are error(s) found with the form you submitted.";
  22.         echo "These error(s) appear below.<br /><br />";
  23.         echo $error. "<br /><br />";
  24.         echo "Please go back and fix these errors <br />";
  25.         die();
  26.       }
  27.  
  28.     function clean_string($string)
  29.       {
  30.         // Sanitization
  31.         $bad = array("content-type", "bcc", "to:", "cc:", "href");
  32.         return str_replace($bad, "", $string);
  33.       }
  34.  
  35.     //*** Functions end ***/
  36.  
  37.     //*** Validation start ***/
  38.  
  39.     $error_message ="";
  40.  
  41.     if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['msg']))
  42.       {
  43.         $error_message .= 'We are sorry but there appears to be a problem with the form you submitted.<br />';
  44.       }
  45.  
  46.     // Expected Strings
  47.  
  48.  // $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}$/';
  49.     $email_exp = "/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i";
  50.  
  51.     if(!preg_match($email_exp, $email))
  52.       {
  53.         $error_message .= 'The Email address you entered does not appear to be valid.<br />';
  54.       }
  55.  
  56.  // $string_exp = "/^[A-Za-z.'-]+$/";
  57.     $string_exp = "/^[A-Za-z ][A-Za-z ]*$/";
  58.  
  59.     if(!preg_match($string_exp, $name))
  60.       {
  61.         $error_message .= 'The Name you entered does not appear to be valid.<br />';
  62.       }
  63.  
  64. //  $string_exp = "/^[A-Za-z0-9.'-]+$/";
  65.     $string_exp = "/^[A-Za-z0-9.,'\- ][A-Za-z0-9.,'\- ]+$/";
  66.  
  67.     if(!preg_match($string_exp, $msg) || (strlen(trim($msg)) < 2))
  68.       {
  69.         $error_message .= 'The message you entered does not appear to be valid.<br />';
  70.       }
  71.  
  72.     if(strlen($error_message)>0)
  73.       {
  74.         died($error_message);
  75.       }
  76.  
  77.     $email_message = "Name: " . clean_string($name) . "\n";
  78.     $email_message .= "Email: " . clean_string($email) . "\n";
  79.     $email_message .= "Phone: " . clean_string($phone) . "\n";
  80.     $email_message .= "Message: " . clean_string($msg) . "\n";
  81.  
  82.     //*** Validation end ***/
  83.  
  84.     // Create Email Headers
  85.  
  86.     $headers = 'From: ' .$email_from. "\r\n";
  87.     $headers .= 'Reply-To:' . $email . "\r\n";
  88.     $headers .= 'Return-Path: ' . $email_from . "\r\n";
  89.     $headers .= 'MIME-Version: 1.0' . "\r\n";
  90.     $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
  91.  
  92.  
  93. if(mail($email_to, $email_subject, $email_message, $headers))
  94.   {
  95.     // Success Message Goes Here
  96.     echo "Thank you for contacting us. We will get back to you shortly.<br />";
  97.   }
  98.   else
  99.     {
  100.       died("there was some type of error while sending the Email");
  101.     }
  102. }
  103. ?>
RAW Paste Data