<?php
session_start();
require 'functions.php';
date_default_timezone_set('America/New_York');
$date = date("F j, Y, g:i a");


if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // $to = 'marketing@raptormedia.co'; // Replace with your email address
    $recipients = array(
    "quinn.dolan@dxtxpas.com",
    "mack@dxtxpas.com",
    "john.src@sbcglobal.net"
    );
    $to = implode(',', $recipients);
    $subject = 'New Quote Request From SPINAL RECOVERY CENTER';

    // Collect form data
    $firstName = $_POST['first-name'];
    $lastName = $_POST['last-name'];
    $cellPhone = $_POST['cell-phone'];
    $repairNeeds = isset($_POST['repair-needs']) ? implode(', ', $_POST['repair-needs']) : 'None';
    // $panelsReplaced = $_POST['panels-replaced'];
    $additionalDetails = $_POST['additional-details'];

    // Construct email body
    $message = "SPINAL RECOVERY CENTER:\n\n";
    $message .= "First Name: $firstName\n";
    $message .= "Last Name: $lastName\n";
    $message .= "Cell Phone: $cellPhone\n";
    $message .= "How can we help you: $repairNeeds\n";
    // $message .= "Panels Replaced: $panelsReplaced\n";
    $message .= "Additional Details: $additionalDetails";

    // Send the email
    $headers = 'From: no-reply@raptormedia.co' . "\r\n";  // Replace with your "from" email address
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    

    if (mail($to, $subject, $message, $headers)) {
        // $url =  '../contact.php?success=1';
        // $url =  $_SERVER['HTTP_REFERER'] . '#success';
        $url =  $_SERVER['HTTP_REFERER'] . '?success=1';
          header("location: $url");
        exit();
        // echo 'Email sent successfully!';
    } else {
        // $url =  '../contact.php?error=1';
        $url =  $_SERVER['HTTP_REFERER'] . '?error=1';
        header("location: $url");
        exit();

        // echo 'Failed to send email.';
    }
}
?>
