Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['email'])) {
  3.     // CHANGE THE TWO LINES BELOW
  4.     $email_to = "contact@data1.nl";
  5.     $email_subject = "Contact via Data1.nl";
  6.     function died($error) {
  7.         // your error code can go here
  8.         echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  9.         echo "These errors appear below.<br /><br />";
  10.         echo $error . "<br /><br />";
  11.         echo "Please go back and fix these errors.<br /><br />";
  12.         die();
  13.     }
  14.     // validation expected data exists
  15.     if (!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) {
  16.         died('We are sorry, but there appears to be a problem with the form you submitted.');
  17.     }
  18.     $first_name = $_POST['first_name']; // required
  19.     $last_name = $_POST['last_name']; // required
  20.     $email_from = $_POST['email']; // required
  21.     $telephone = $_POST['telephone']; // not required
  22.     $comments = $_POST['comments']; // required
  23.     $verification = $_POST['verification']; // required
  24.  
  25.     $error_message = "";
  26.     $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  27.     if (!preg_match($email_exp, $email_from)) {
  28.         $error_message.= 'The Email Address you entered does not appear to be valid.<br />';
  29.     }
  30.     $string_exp = "/^[A-Za-z .'-]+$/";
  31.     if (!preg_match($string_exp, $first_name)) {
  32.         $error_message.= 'The First Name you entered does not appear to be valid.<br />';
  33.     }
  34.     if (!preg_match($string_exp, $last_name)) {
  35.         $error_message.= 'The Last Name you entered does not appear to be valid.<br />';
  36.     }
  37.     if (strlen($comments) < 2) {
  38.         $error_message.= 'The Comments you entered do not appear to be valid.<br />';
  39.     }
  40.     if($verification !== '11') {
  41.         $error_message.= 'Verification failed<br />';
  42.     }
  43.  
  44.     if (strlen($error_message) > 0) {
  45.         died($error_message);
  46.     }
  47.     $email_message = "Formulier gegevens:.\n\n";
  48.     function clean_string($string) {
  49.         $bad = array("content-type", "bcc:", "to:", "cc:", "href");
  50.         return str_replace($bad, "", $string);
  51.     }
  52.     $email_message.= "Voornaam: " . clean_string($first_name) . "\n";
  53.     $email_message.= "Achternaam: " . clean_string($last_name) . "\n";
  54.     $email_message.= "Email: " . clean_string($email_from) . "\n";
  55.     $email_message.= "Telefoon: " . clean_string($telephone) . "\n";
  56.     $email_message.= "Het Bericht: " . clean_string($comments) . "\n";
  57.     // create email headers
  58.     $headers = 'From: ' . $email_from . "\r\n" . 'Reply-To: ' . $email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
  59.     @mail($email_to, $email_subject, $email_message, $headers);
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement