<?php
/** 
  * This is a sample appointment form to demonstrate how
  * Form2Mail works.
  * The default mail transport is sendmail ( not PHP mail() )
  * Also supported, in order, are PHPMailerLite.php or PHPMailer Pro.php
  */

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$show_form   = true;
$reload_form = true;

if (count($_POST) > 0) {

  /**
   * Check if the hidden honeypot fields are filled out. If not, send a mail.
   * there are two honeypot fields, both are initially set with an empty value
   * if any are filled in, a bot or hacker is at work, reject
   */
  $hacker = false;
  if ( isset($_POST['hpot_url']) && !empty($_POST['hpot_url'])) { $hacker=true;unset($_POST['hpot_url']); }
  if ( isset($_POST['hpot_okurl'])   && !empty($_POST['hpot_okurl']))   { $hacker=true;unset($_POST['hpot_okurl']); }
  if ( $hacker === true ) { exit('Unable to process<br>'); }
  $hacker = null;unset($hacker);
  /* END honeypot bot/hacker check */

  /* VALIDATION */
  require('assets/mailer/FormValidator.php');
  $validator = new codeworxtech\FormValidator('en');

  $validator->addValidation("Name","required","Full name is required.");
  $validator->addValidation("Name","nourl","No URL allowed.");
  $validator->addValidation("Email","required","Email address is required.");
  $validator->addValidation("Email","email","Provide a valid email address.");
  $validator->addValidation("Message","mandatory","Message is required.");
  $validator->addValidation("Message","nourl","No URL allowed.");

  if($validator->ValidateForm()) {
    $required      = 'Name,Email,Message';
    $reserved_keys = 'hpot_url,hpot_okurl';

    $setSender     = ['noreply@' . $_SERVER['HTTP_HOST']=>'No Reply (unmonitored)'];
    $setRecipient  = ['yourname@yourdomain.com'=>'Your Name'];
    $subject       = 'Contact Us Form from: ' . $_SERVER['HTTP_HOST'];
    $useEnvRpt     = false;
    $refreshWaitMinutes = 0;
    $redirect      = "sample_thankyou.php?t=contactus";

  //  $SMTP_Host     = 'smtp.yourhost.com';
  //  $SMTP_Account  = [ 'youraccount@yourhost.com' => 'yourpassword' ];

    require 'assets/mailer/Form2Mail.php';
    exit();
  } else {
    $error_hash = $validator->GetErrors();
    $error_dump = '';
    foreach($error_hash as $inpname => $inp_err) {
      $errorVar  = $inpname . '_error';
      $$errorVar = '<br><span id="' . $errorVar . '" class="s_error">&#9650; ' . $inp_err . '</span>';
    }
    foreach ($_POST as $key => $val) {
      $$key = $val;
    }
  }
}
?><!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Form2Mail Sample Contact Us form</title>
  <link href="https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;500;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.2/css/bulma.min.css" />
<style>
.required {
  font-size:0.8rem;
  color:red;
}
</style>
</head>
<body>
<section class="container">
  <div class="columns is-multiline">
    <div class="column is-10 is-offset-1">
      <div class="columns">
        <div class="column left">
          <h1 class="title is-1">Form2Mail<br>Sample<br>Contact Us</h1>
          <h2 class="subtitle colored is-4">To fully test this sample form:</h2>
          <p>
            To fully test, add your email address to $setRecipient
            in the php code at the top of this form ... then go ahead and submit a test.
          </p>
        </div>
        <div class="column right has-text-left">
          <form method="POST"  enctype="multipart/form-data">
          <div class="field">
            <label class="label" for="Name">Name <span class="required">&#10033;</span></label>
            <div class="control">
              <input class="input is-medium" type="text" name="Name" value="<?php echo (isset($Name)) ? $Name : ''; ?>" required autofocus />
              <?php echo isset($Name_error) ? $Name_error : ''; ?>
            </div>
          </div>
          <div class="field">
            <label class="label" for="Email">Email <span class="required">&#10033;</span></label>
            <div class="control">
              <input class="input is-medium" type="text" name="Email" value="<?php echo (isset($Email)) ? $Email : ''; ?>" required />
              <?php echo isset($Email_error) ? $Email_error : ''; ?>
            </div>
          </div>
          <div class="field">
            <label class="label" for="Message">Message <span class="required">&#10033;</span></label>
            <div class="control">
              <textarea class="textarea is-medium" name="Message" required><?php echo (isset($Message)) ? $Message : ''; ?></textarea>
              <?php echo isset($Message_error) ? $Message_error : ''; ?>
            </div>
          </div>

          <div class="field">
            <label class="label" for="File1">Upload </label>
            <div class="control">
              <input name="File1" type="file" />>
            </div>
          </div>

          <div class="field is-viz">
            <label class="label" for="hpot_url">Leave blank and submit</label>
            <div class="control">
              <input class="input is-medium" type="text" id="hpot_url" name="hpot_url" value="" placeholder="Your website url, include http or https" autocomplete="off" />
            </div>
          </div>
          <div class="field is-viz">
            <label class="label" for="hpot_okurl">Leave unchecked to submit</label>
            <div class="control">
              <input type="checkbox" id="hpot_okurl" name="hpot_okurl" value="" />
            </div>
          </div>
          <div class="control">
            <input class="button is-link is-fullwidth has-text-weight-medium is-medium" type="submit" value="Send Message" name="Submit">
          </div>
          </form>
          <span class="required">&#10033;</span> = required<br>
        </div>
      </div>
    </div>
    <div class="column is-8 is-offset-2">
      <br>
      <nav class="level">
        <div class="level-left">
          <div class="level-item">
          <span class="icon">
            <a href="https://twitter.com/PHPMailer_2" target="_blank">
            <i class="fa fa-twitter fa-lg" title="Follow on Twitter"></i>
            </a>
          </span> &emsp;
          <span class="icon">
            <a href="https://www.facebook.com/groups/phpmailer2" target="_blank">
            <i class="fa fa-facebook fa-lg" title="Follow on Facebook"></i>
            </a>
          </span> &emsp;
          <span class="icon">
            <i class="fa fa-github fa-lg" title="Follow on Github"></i>
          </span> &emsp;
          <span class="icon">
            <a href="&#109&#97&#105&#108&#116&#111&#58&#97;&#110;&#100;&#121;&#64;&#99;&#111;&#100;&#101;&#119;&#111;&#114;&#120;&#116;&#101;&#99;&#104;&#46;&#99;&#111;&#109;?subject=Contact%20Us%20form%20enquiry&body=I%20am%20interested%20%0D%0A%0D%0A" rel="nofollow"
            <i class="fa fa-envelope fa-lg" title="Send an Email"></i>
            </a>
          </span>
          </div>
        </div>
        <div class="level-right">
          <small class="level-item" style="color: var(--textLight)">
          &copy; Your Copyright Message Here. All Rights Reserved.
          </small>
        </div>
      </nav>
    </div>
  </div>
</section>
</body>
<style>
:root {
  --brandColor: hsl(166, 67%, 51%);
  --background: rgb(247, 247, 247);
  --textDark: hsla(0, 0%, 0%, 0.66);
  --textLight: hsla(0, 0%, 0%, 0.33);
}
body {
  background: var(--background);
  height: 100vh;
  color: var(--textDark);
}
.field:not(:last-child) {
  margin-bottom: 1rem;
}
.register {
  margin-top: 10rem;
  background: white;
  border-radius: 10px;
}
.left,
.right {
  padding: 2.5rem;
}
.left {
  border-right: 5px solid var(--background);
}
.left .title {
  font-weight: 800;
  letter-spacing: -2px;
}
.left .colored {
  color: var(--brandColor);
  font-weight: 500;
  margin-top: 1rem !important;
  letter-spacing: -1px;
}
.left p {
  color: var(--textLight);
  font-size: 1.15rem;
}
.right .title {
  font-weight: 800;
  letter-spacing: -1px;
}
.right .description {
  margin-top: 1rem;
  margin-bottom: 1rem !important;
  color: var(--textLight);
  font-size: 1.15rem;
}
.right small {
  color: var(--textLight);
}
input {
  font-size: 1rem;
}
input:focus {
  border-color: var(--brandColor) !important;
  box-shadow: 0 0 0 1px var(--brandColor) !important;
}
.fa {
  color: var(--textLight);
  margin-right: 1rem;
}
.is-viz {
  display:none;
}
</style>
</html>

