Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $patterns = [
- "name" => "/^[a-z ,.'-]+$/i",
- "email" => "/^[\w&]([\w\-\.'&]*)@([\w\-\.]*)(\.[a-z]{2,6}(\.[a-z]{2}){0,2})$/i",
- "subject" => "/^(?!\s*$).+/",
- "message" => "/^(?!\s*$).+/"
- ];
- $values = [
- "name" => "",
- "email" => "",
- "subject" => "",
- "message" => ""
- ];
- $errors = [];
- $title = "Contact Us";
- if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
- foreach ( $values as $key => $value ) {
- $values[$key] = trim($_POST[$key]);
- if ( !preg_match($patterns[$key], $values[$key]) ) {
- $errors[] = $key;
- }
- }
- if ( empty( $errors ) ) {
- $from = "From: ".$values['name'];
- $to = "black-owling@outlook.com";
- $subjectMessage = $values['name'] . " writes about: " . $values['subject'];
- $mailMessage = "Message from contact form of ShopifyWizz webpage. \n".
- "Sent by ".$values['name']." (".$values['email'].") \n".
- "User writes following: \n".
- $values['message'];
- $mailSent = mail($to, $subjectMessage, $mailMessage, $from);
- if ( $mailSent ) {
- $title = "Thank you!";
- } else {
- $title = "Sorry, we couldn't send your letter.";
- }
- }
- }
- include 'header.php';
- ?>
- <main class="contact">
- <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>
- <?php if ( !empty($errors) ) { ?>
- <p class="notification">Specified fields are invalid. Please ensure that information is correct and try again.</p>
- <?php } ?>
- <?php if ( $mailSent == true ) { ?>
- <p class="notification">Thank you for your message. We will contact you as soon as possible!</p>
- <?php } ?>
- <form action="contact.php" id="contact-form" method="POST" novalidate>
- <div class="form-part <?php if(in_array( "name", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="name">Name</label>
- <input type="text"
- id="name"
- name="name"
- required="required"
- data-pattern="plainText"
- value="<?= $values["name"] ?>">
- </div>
- <div class="form-part <?php if(in_array( "email", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="email">E-mail</label>
- <input type="email"
- id="email"
- name="email"
- required="required"
- data-pattern="email"
- value="<?= $values["email"] ?>">
- </div>
- <div class="form-part <?php if(in_array( "subject", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="theme">Subject</label>
- <input type="text"
- id="theme"
- name="subject"
- required="required"
- data-pattern="anyString"
- value="<?= $values["subject"] ?>">
- </div>
- <div class="form-part msg-container <?php if(in_array( "message", $errors ) ) echo "ui-state-invalid" ?>">
- <label for="message">message</label>
- <textarea name="message"
- id="message"
- placeholder="Drop us a message"
- required="required"
- data-pattern="anyString"><?= $values["message"] ?></textarea>
- </div>
- <input type="submit" class='button'>
- </form>
- </main>
- <?php
- include 'footer.php';
- ?>
- <script src='js/jquery.min.js'></script>
- <script src='js/misc.js'></script>
- <script src="js/jquery.guardian.min.js"></script>
- <script src="js/ajaxform.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement