How can PHP be used to send form data without redirecting to a new page, especially in the context of a One-Page-Site?

To send form data without redirecting to a new page in a One-Page-Site, you can use AJAX with PHP. This allows the form submission to happen in the background without refreshing the page, providing a seamless user experience. By utilizing AJAX, you can send the form data to a PHP script, process it, and receive a response without disrupting the current page's content.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data here
    $name = $_POST['name'];
    $email = $_POST['email'];
    
    // Example: Sending a response back
    echo "Form submitted successfully!";
    exit;
}
?>