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

    $child_name = $_POST['child_name'] ?? 'Unknown Child';
    $first_name = $_POST['first_name'] ?? '';
    $last_name  = $_POST['last_name'] ?? '';
    $email      = $_POST['email'] ?? '';
    $phone      = $_POST['phone'] ?? '';
    $amount     = $_POST['amount'] ?? '';

    $to = "info@wipetearsafrica.org";
    $subject = "New Child Sponsorship Submission";

    $message = "New Sponsor Details\n\n";
    $message .= "Child Sponsored: $child_name\n\n";
    $message .= "First Name: $first_name\n";
    $message .= "Last Name: $last_name\n";
    $message .= "Email: $email\n";
    $message .= "Phone: $phone\n";
    $message .= "Sponsorship Plan: $amount\n";

    $headers  = "From: Wipe Tears Africa <no-reply@wipetearsafrica.org>\r\n";
    $headers .= "Reply-To: $email\r\n";

    mail($to, $subject, $message, $headers);

    header("Location: /thank-you.html");
    exit;
}
