What best practices should be followed when creating a contact script in PHP to ensure it is easily expandable and customizable?

When creating a contact script in PHP, it is important to follow best practices to ensure it is easily expandable and customizable. One way to achieve this is by separating the logic into different functions or classes, making it easier to add new features or modify existing ones without affecting the entire script. Additionally, using configuration files or constants for settings such as email addresses or message templates can make the script more flexible and reusable.

<?php

// Define configuration settings
define('CONTACT_EMAIL', 'contact@example.com');
define('SUCCESS_MESSAGE', 'Your message has been sent successfully.');

// Function to send email
function sendEmail($to, $subject, $message) {
    // Use PHP's mail function to send email
    // Add any additional email sending logic here
}

// Function to process contact form submission
function processContactForm($name, $email, $message) {
    // Validate form data
    // Sanitize input
    // Send email using sendEmail function
    sendEmail(CONTACT_EMAIL, 'Contact Form Submission', $message);

    return SUCCESS_MESSAGE;
}

// Example usage
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $result = processContactForm($name, $email, $message);
    echo $result;
}

?>