What are some best practices for using PHP to create a contact form on multiple pages?

When creating a contact form that appears on multiple pages, it is best to create a separate PHP file for the form processing logic and include this file in each page where the form is displayed. This way, you can reuse the same code and easily make changes to the form processing without having to update multiple pages.

<?php
// contact_form.php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form submission
    $name = $_POST["name"];
    $email = $_POST["email"];
    $message = $_POST["message"];
    
    // Additional validation and processing logic here
    
    // Send email or save to database
}
?>

<form method="post" action="contact_form.php">
    <input type="text" name="name" placeholder="Your Name">
    <input type="email" name="email" placeholder="Your Email">
    <textarea name="message" placeholder="Your Message"></textarea>
    <button type="submit">Submit</button>
</form>