<html>
<head>
<!-- Redirect to thank you page -->
<meta http-equiv="refresh" content="0; url='https://www.varinosdental.com/thankyou.html'" />
</head>
<body>
<?php

//collect submitted data, time/date, and URL form is submitted from
$output;
$date = date("Y-m-d");
$time = date("h:i:sa");
$page = $_SERVER['HTTP_REFERER'];

// hide irrelevant POST data like recaptcha
$hideKeys = array("_token", "g-recaptcha-response", "practice_id", "location_id", "doctor_id");



// locations

$location_ids = array(
    "23361"=>"Newburyport",
    "23363"=>"Peabody",
    "23366"=>"Winthrop"
);





// doctors

$doctor_ids = array(
"3849128794"=>"Frank  T Varinos, DMD",
"3849128795"=>"Jemin Kim, DMD, MA",
"3849151259"=>"Stephen  Coletti, DMD",
"3849151260"=>"Douglas Chespak, DDS",
"3849151262"=>"Alison Towns, DMD"
);





foreach ($_POST as $key => $value) {
    
    if(!empty($value) && !in_array($key, $hideKeys)  && !in_array($key, $location_ids) && !in_array($key, $doctor_ids)) {
        
        $values .= $key . ": " . $value . "\n";
    
    }
    
    
    if ($key == 'location_id') {
        
    $values .= "Office Location: " . $location_ids[$value]. "\n";
        
    }
    
    
        
    if ($key == 'doctor_id') {
        
    $values .= "Doctor Requested: " . $doctor_ids[$value]. "\n";
        
    }
        
    
    
    
}


$output = "Date/Time: " . $date . " - " . $time . "\n" . "Page URL: " . $page . "\n" . $values . "\n";
$output = htmlspecialchars($output);

// write submitted data to text file
$myfile = fopen("submissions.txt", "a") or die("form error</br>");
fwrite($myfile, $output . "\n");
fclose($myfile);
echo "Thanks for contacting us! Your request has been submitted.</br>";
echo '<a href="https://www.varinosdental.com/thankyou.html">Please click here if you are not automatically redirected.</a>';

// show debug output
//echo '<pre>' . $output; '</pre>';

if(!empty($_POST['name'])) {
// send submitted data as email to client
$email = 'newburyport@varinosdental.com, winthrop@varinosdental.com, peabody@varinosdental.com, pamela@varinosdental.com, erick@getfoundquick.com, connor@getfoundquick.com, Varinosdentalassociate@gmail.com';
$headers .= 'From: "Varinos Dental Website" <donotreply@bwmsites.com>' . "\r\n";

// real mail
mail($email, 'New Contact Form - ' . $date . ' ' . $time , $output, $headers);

$debug_email = "connor@getfoundquick.com";    
//debug mail    
//mail($debug_email, 'New Contact Form - ' . $date . ' ' . $time , $output, $headers);
    
}
?>
</body>
</html>