false, 'error' => 'Method not allowed']); exit; } // ── CONFIG ──────────────────────────────────────────────────────────── define('SENDGRID_API_KEY', 'SG.YOUR_KEY_HERE'); // <-- replace with your SendGrid API key define('MAIL_FROM', 'noreply@parkerslingshotrentals.com'); define('MAIL_FROM_NAME', 'Parker County Slingshot Rentals'); define('ADMIN_EMAIL', 'info@parkerslingshotrentals.com'); // where booking alerts go // ───────────────────────────────────────────────────────────────────── $input = json_decode(file_get_contents('php://input'), true); if (!$input) { $input = $_POST; } $name = trim(strip_tags($input['name'] ?? '')); $email = trim(strip_tags($input['email'] ?? '')); $phone = trim(strip_tags($input['phone'] ?? '')); $package = trim(strip_tags($input['package'] ?? '')); $date = trim(strip_tags($input['date'] ?? '')); $message = trim(strip_tags($input['message'] ?? '')); // Basic validation if (!$name || !$email || !$package || !$date) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Name, email, package, and date are required.']); exit; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid email address.']); exit; } $packages = [ 'half-day' => 'Half Day (4 hrs) — $99', 'full-day' => 'Full Day (8 hrs) — $169', 'weekend' => 'Weekend (48 hrs) — $299', ]; $packageLabel = $packages[$package] ?? ucfirst($package); $dateFormatted = date('F j, Y', strtotime($date)); // ── SEND ADMIN ALERT ────────────────────────────────────────────────── $adminHtml = '

New Booking Request!

Parker County Slingshot Rentals

Name ' . htmlspecialchars($name) . '
Email ' . htmlspecialchars($email) . '
Phone ' . (htmlspecialchars($phone) ?: 'not provided') . '
Package ' . htmlspecialchars($packageLabel) . '
Date ' . htmlspecialchars($dateFormatted) . '
' . ($message ? '

' . nl2br(htmlspecialchars($message)) . '

' : '') . '

Submitted ' . date('F j, Y \a\t g:i A') . ' CT

'; // ── SEND CUSTOMER CONFIRMATION ──────────────────────────────────────── $confirmHtml = '

Parker County Slingshot Rentals

Booking Request Received!

Hey ' . htmlspecialchars($name) . ', we got your request and will confirm availability within a few hours.

Your Request Summary

Package: ' . htmlspecialchars($packageLabel) . '

Requested Date: ' . htmlspecialchars($dateFormatted) . '

We\'ll reach out to you at ' . htmlspecialchars($email) . '' . ($phone ? ' or ' . htmlspecialchars($phone) . '' : '') . ' to confirm your ride.

Questions? Call or text us at (817) 555-0199.

Ride on,
The Parker County Slingshot Team

© ' . date('Y') . ' Parker County Slingshot Rentals — Weatherford, TX

'; function sendgridSend(string $toEmail, string $toName, string $subject, string $html): bool { $payload = json_encode([ 'personalizations' => [['to' => [['email' => $toEmail, 'name' => $toName]]]], 'from' => ['email' => MAIL_FROM, 'name' => MAIL_FROM_NAME], 'subject' => $subject, 'content' => [['type' => 'text/html', 'value' => $html]], ]); $ch = curl_init('https://api.sendgrid.com/v3/mail/send'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . SENDGRID_API_KEY, 'Content-Type: application/json', ], CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false, ]); $response = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $code === 202; } $apiKey = SENDGRID_API_KEY; if ($apiKey && strpos($apiKey, 'YOUR_KEY') === false) { sendgridSend(ADMIN_EMAIL, 'Parker Slingshot Admin', "New Booking Request: {$name} — {$packageLabel} on {$dateFormatted}", $adminHtml); sendgridSend($email, $name, "Booking Request Confirmed — Parker County Slingshot", $confirmHtml); } else { error_log('[Parker Slingshot] SENDGRID_API_KEY not configured'); } echo json_encode(['success' => true, 'message' => 'Booking request received! We\'ll be in touch shortly.']);