<?php
// Basic validation
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $name = trim($_POST['name'] ?? '');
  $email = trim($_POST['email'] ?? '');
  $message = trim($_POST['message'] ?? '');

  if ($name && $email && $message) {
    $to = 'vader0ne@yahoo.com';
    $subject = "New Contact Form Message from $name";
    $body = "You received a new message from Home Time Radio:\n\n";
    $body .= "Name: $name\n";
    $body .= "Email: $email\n\n";
    $body .= "Message:\n$message\n";

    $headers = "From: $email\r\n";
    $headers .= "Reply-To: $email\r\n";

    if (mail($to, $subject, $body, $headers)) {
      header('Location: /contact-success.php');
      exit;
    } else {
      echo "<div class='alert alert-danger'>Message could not be sent. Please try again later.</div>";
    }
  } else {
    echo "<div class='alert alert-warning'>Please fill in all fields.</div>";
  }
} else {
  echo "<div class='alert alert-warning'>Invalid request.</div>";
}
?>
