<?php
require('includes/config.php');
require("process-email.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Include PHPMailer files
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$msg = "";
$errors = [];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

  $name     = trim($_POST['name'] ?? '');
  $plate    = trim($_POST['plate'] ?? '');
  $vin      = trim($_POST['vin'] ?? '');
  $pickup   = trim($_POST['pickup'] ?? '');
  $dropoff  = trim($_POST['dropoff'] ?? '');
  $make     = trim($_POST['make'] ?? '');
  $year     = trim($_POST['year'] ?? '');
  $amount   = trim($_POST['amount'] ?? '');
  $human    = trim($_POST['human'] ?? '');
  $email    = trim($_POST['email'] ?? '');
    // Only 'amount' is required
    if (empty($amount)) {
        $errors['amount'] = "Amount is required.";
    }

    // Optional human check (if you want it)
    if (!empty($human) && $human != '5') {
        $errors['human'] = "Anti-spam answer is incorrect.";
    }
  if (empty($errors)) {
        $invoiceNumber = 'APT'.strtoupper(substr(md5(uniqid(rand(), true)),0,8));
        $mail = new PHPMailer(true);
        try {
            $mail->isSMTP();
            $mail->Host       = 'smtp.gmail.com';
            $mail->SMTPAuth   = true;
            $mail->Username   = 'aplustowingltd@gmail.com';
            $mail->Password   = 'ddbmadsiylkvobho';
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
            $mail->Port       = 465;

            $mail->setFrom('aplustowingltd@gmail.com', 'Emergency Towing Request');
            $mail->addAddress('websmartquick@gmail.com', 'Admin');
            if (!empty($email)) {
                $mail->addReplyTo($email, $name);
            }

            $mail->isHTML(true);
            $mail->Subject = "Emergency Towing Request - Order #: $invoiceNumber";
            $mail->Body    = "
                <h2>Emergency Towing Request</h2>
                <h3>Order Number: $invoiceNumber</h3>
                <table cellpadding='5' cellspacing='0' border='1' width='100%'>
                    <tr><td><strong>Company Name</strong></td><td>$name</td></tr>
                    <tr><td><strong>Plate/Unit Number</strong></td><td>$plate</td></tr>
                    <tr><td><strong>Email</strong></td><td>$email</td></tr>
                    <tr><td><strong>VIN Number</strong></td><td>$vin</td></tr>
                    <tr><td><strong>Pickup Location</strong></td><td>$pickup</td></tr>
                    <tr><td><strong>Dropoff Location</strong></td><td>$dropoff</td></tr>
                    <tr><td><strong>Make/Model</strong></td><td>$make</td></tr>
                    <tr><td><strong>Amount</strong></td><td>$amount</td></tr>
                    <tr><td><strong>Year</strong></td><td>$year</td></tr>
                </table>
            ";
         
            $mail->send();

            header("Location: https://link.clover.com/urlshortener/2dJqFY");
            ob_end_flush();
            exit();

        } catch (Exception $e) {
          echo "Mailer Error: " . $mail->ErrorInfo;
          exit();
      }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Google Tag Manager -->
  <script>
    (function(w, d, s, l, i) {
      w[l] = w[l] || [];
      w[l].push({
        'gtm.start':
          new Date().getTime(),
        event: 'gtm.js'
      });
      var f = d.getElementsByTagName(s)[0],
        j = d.createElement(s),
        dl = l != 'dataLayer' ? '&l=' + l : '';
      j.async = true;
      j.src =
        'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
      f.parentNode.insertBefore(j, f);
    })(window, document, 'script', 'dataLayer', 'GTM-MKPHNBN9');
  </script>
  <!-- End Google Tag Manager -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="description" content="Located in Edmonton servicing Edmonton, Grande Prairie, Fort Mcmurray and surrounding areas.A Plus Towing And Recovery is the first-choice source for towing services and roadside assistance. Our clients appreciate our fast dispatch times, competitive rates, and five-star customer service." />
  <meta name="abstract" content="A Plus Towing And Recovery is the premier tow truck company in town, thanks to our swift response times, friendly service, and safe, sound towing practices. Our company boasts a state-of-the-art fleet of flatbed trucks so you can have peace of mind knowing that your vehicle is secure from start to finish.. Our Trucks are on road near you 24 Hours for , hauling, and emergency roadside assistance needs.Are you stuck on the side of the road? Let�s change that. Give our licensed technicians a call at (780) 804-6000 to book an appointment and get your day back on track." />
  <meta name="robots" content="follow, index" />
  <link rel="canonical" href="https://aplustow.ca/" />
  <link rel="shortlink" href="https://aplustow.ca/" />
  <meta http-equiv="content-language" content="en" />
  <meta name="geo.position" content="53.5038460;-113.3558020" />
  <meta name="geo.region" content="CA-AB" />
  <meta name="icbm" content="53.5038460,-113.3558020" />
  <meta name="dcterms.title" content="A Plus Towing & Recovery" />
  <meta name="dcterms.description" content="A Plus Towing & Recovery " />
  <meta name="dcterms.type" content="Text" />
  <meta name="dcterms.format" content="text/html" />
  <meta name="dcterms.identifier" content="https://aplustow.ca/" />
  <link rel="icon" type="image/png" href="assets/img/favicon.png">
  <title>A Plus | Towing & Recovery </title>
  <title>A Plus Towing & Recovery Services|Contact</title>
  <!-- Google Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
  <link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" media="all" />
  <!-- Vendor CSS Files -->
  <link href="assets/vendor/animate.css/animate.min.css" rel="stylesheet">
  <link href="assets/vendor/aos/aos.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">
</head>
<body>
  <?php require 'header.php'; ?>
  <main id="main">
    <section id="breadcrumbs" class="breadcrumbs">
      <div class="container">
        <nav style="--bs-breadcrumb-divider: url(&#34;data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='currentColor'/%3E%3C/svg%3E&#34;);" aria-label="breadcrumb">
          <ol class="breadcrumb">
            <li><a href="index.php">Home</a></li>
            <li class="breadcrumb-item active" aria-current="page">Company/Truck Information</li>
          </ol>
        </nav>
        <h2>Company/Truck Information</h2>
      </div>
    </section>
    <div class="container mt-5 mb-5">
      <h1>Company/Truck Information</h1>
      <p>Please fill out the form below to request a towing service. We will get back to you as soon as possible.</p>
      <form class="form-inline" role="form" method="post" action="">
        <div class="row">
          <div class="col-md-6 form-group">
            <label class="control-label">Company Name</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Company Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
           
          </div>
          <div class="col-md-6 form-group mt-3 mt-md-0 mb-3">
            <label class="control-label">Plate/Unit Number</label>
            <input type="text" class="form-control" id="plate" name="plate" placeholder="Plate/Unit Number" value="<?php echo htmlspecialchars($_POST['plate']); ?>" >
         
          </div>
            <div class="col-md-6 form-group mt-3 mb-3 mt-md-0">
            <label class="control-label">Email</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="email" value="<?php echo htmlspecialchars($_POST['email']); ?>" >
         
          </div>


          <div class="col-md-6 form-group mt-3 mt-md-0">
            <label class="control-label">Vin Number</label>
            <input type="text" class="form-control" id="vin" name="vin" placeholder="Vin Number" value="<?php echo htmlspecialchars($_POST['vin']); ?>" >
         
          </div>
          <div class="col-md-6 form-group mt-3 mb-3 mt-md-0">
            <label class="control-label">Pickup Location</label>
            <input type="text" class="form-control" id="pickup" name="pickup" placeholder="Pickup Location" value="<?php echo htmlspecialchars($_POST['pickup']); ?>" >
         
          </div>
          <div class="col-md-6 form-group ">
            <label class="control-label">Drop Off Location</label>
            <input type="text" class="form-control" id="dropoff" name="dropoff" placeholder="Drop Off Location" value="<?php echo htmlspecialchars($_POST['dropoff']); ?>" >
         
          </div>
          <div class="col-md-6 form-group mt-3 mb-3 mt-md-0">
            <label class="control-label">Make/Model</label>
            <input type="text" class="form-control" id="make" name="make" placeholder="Make/Model" value="<?php echo htmlspecialchars($_POST['make']); ?>" >
       
          </div>
          <div class="col-md-6 form-group ">
            <label class="control-label">Amount </label>
            <input type="text" class="form-control" name="amount" value="<?php echo htmlspecialchars($_POST['amount'] ?? ''); ?>" required>
            <?php if(!empty($errors['amount'])) echo "<p class='text-danger'>{$errors['amount']}</p>"; ?>
          </div>
         

          <div class="col-md-6 form-group mt-3 mt-md-0">
            <label class="control-label">Year</label>
            <input type="text" class="form-control" id="year" name="year" placeholder="Year" value="<?php echo htmlspecialchars($_POST['year']); ?>" >
     
          </div>


          <div class="col-md-6 form-group mt-3 mt-md-0">
            <label>2 + 3 = ?</label>
            <input type="text" class="form-control" name="human" value="<?php echo htmlspecialchars($_POST['human'] ?? ''); ?>">
            <?php if(!empty($errors['human'])) echo "<p class='text-danger'>{$errors['human']}</p>"; ?>
          </div>
          <div class="my-3">
            <button type="submit" name="submit" class="button" style="vertical-align:middle"><i class="fa bigicon padd"></i> <span> Send Message </span></button>
            <?php echo $msg; ?>
          </div>
      </form>
    </div>
    <!-- End Breadcrumbs -->
    <!-- ======= About Us Section ======= -->
  </main>
  <?php require 'footer-form.php'; ?>
</body>
</html>