What are the best practices for sending form data without using a mail program in PHP?

When sending form data without using a mail program in PHP, one common approach is to use the PHP `mail()` function to send the form data as an email to a specified email address. This function allows you to specify the recipient, subject, message body, and additional headers. It is important to sanitize and validate the form data before sending it to prevent security vulnerabilities.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $to = "recipient@example.com";
    $subject = "Form Submission";
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    
    $message_body = "Name: $name\nEmail: $email\nMessage: $message";
    
    $headers = "From: sender@example.com";
    
    if (mail($to, $subject, $message_body, $headers)) {
        echo "Form data sent successfully.";
    } else {
        echo "Failed to send form data.";
    }
}
?>