Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.31 KB | None | 0 0
  1. <?php
  2. $patterns = [
  3.     "name" => "/^[a-z ,.'-]+$/i",
  4.     "email" => "/^[\w&]([\w\-\.'&]*)@([\w\-\.]*)(\.[a-z]{2,6}(\.[a-z]{2}){0,2})$/i",
  5.     "subject" => "/^(?!\s*$).+/",
  6.     "message" => "/^(?!\s*$).+/"
  7. ];
  8. $values = [
  9.     "name" => "",
  10.     "email" => "",
  11.     "subject" => "",
  12.     "message" => ""
  13. ];
  14. $errors = [];
  15. $title = "Contact Us";
  16.  
  17. if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
  18.     foreach ( $values as $key => $value ) {
  19.         $values[$key] = trim($_POST[$key]);
  20.         if ( !preg_match($patterns[$key], $values[$key]) ) {
  21.             $errors[] = $key;
  22.         }
  23.     }
  24.  
  25.     if ( empty( $errors ) ) {
  26.         $from = "From: ".$values['name'];
  27.         $to = "black-owling@outlook.com";
  28.  
  29.         $subjectMessage = $values['name'] . " writes about: " . $values['subject'];
  30.  
  31.         $mailMessage =  "Message from contact form of ShopifyWizz webpage. \n".
  32.                     "Sent by ".$values['name']." (".$values['email'].") \n".
  33.                     "User writes following: \n".
  34.                     $values['message'];
  35.  
  36.         $mailSent = mail($to, $subjectMessage, $mailMessage, $from);
  37.  
  38.         if ( $mailSent ) {
  39.             $title = "Thank you!";
  40.         } else {
  41.             $title = "Sorry, we couldn't send your letter.";
  42.         }
  43.  
  44.     }
  45.  
  46. }
  47.  
  48. include 'header.php';
  49.  
  50. ?>
  51.    
  52.     <main class="contact">
  53.         <p>Whether you want to enquire about a quote, find out more about a package or simply say hello – we’d love to hear from you. Fill out the form below and we’ll do our best to get back to you as soon as we can!</p>
  54.  
  55.         <?php if ( !empty($errors) ) { ?>
  56.             <p class="notification">Specified fields are invalid. Please ensure that information is correct and try again.</p> 
  57.         <?php } ?>
  58.  
  59.         <?php if ( $mailSent == true ) { ?>
  60.             <p class="notification">Thank you for your message. We will contact you as soon as possible!</p>
  61.         <?php } ?>
  62.  
  63.         <form action="contact.php" id="contact-form" method="POST" novalidate>
  64.  
  65.             <div class="form-part <?php if(in_array( "name", $errors ) ) echo "ui-state-invalid" ?>">
  66.                 <label for="name">Name</label>
  67.                 <input type="text"
  68.                         id="name"
  69.                         name="name"
  70.                         required="required"
  71.                         data-pattern="plainText"
  72.                         value="<?= $values["name"] ?>">
  73.             </div>
  74.             <div class="form-part <?php if(in_array( "email", $errors ) ) echo "ui-state-invalid" ?>">
  75.                 <label for="email">E-mail</label>
  76.                 <input type="email"
  77.                         id="email"
  78.                         name="email"
  79.                         required="required"
  80.                         data-pattern="email"
  81.                         value="<?= $values["email"] ?>">
  82.             </div>
  83.  
  84.             <div class="form-part <?php if(in_array( "subject", $errors ) ) echo "ui-state-invalid" ?>">
  85.                 <label for="theme">Subject</label>
  86.                 <input type="text"
  87.                         id="theme"
  88.                         name="subject"
  89.                         required="required"
  90.                         data-pattern="anyString"
  91.                         value="<?= $values["subject"] ?>">
  92.             </div>
  93.             <div class="form-part msg-container <?php if(in_array( "message", $errors ) ) echo "ui-state-invalid" ?>">
  94.                 <label for="message">message</label>
  95.                 <textarea name="message"
  96.                             id="message"
  97.                             placeholder="Drop us a message"
  98.                             required="required"
  99.                             data-pattern="anyString"><?= $values["message"] ?></textarea>
  100.             </div>
  101.  
  102.             <input type="submit" class='button'>
  103.         </form>
  104.     </main>
  105.  
  106.     <?php
  107.         include 'footer.php';
  108.     ?>
  109.  
  110.     <script src='js/jquery.min.js'></script>
  111.     <script src='js/misc.js'></script>
  112.     <script src="js/jquery.guardian.min.js"></script>
  113.     <script src="js/ajaxform.js"></script>
  114. </body>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement