Creating a Simple Contact Form Processor in PHP


Process a simple contact form and validate inputs.

Source Code

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = htmlspecialchars($_POST['name']);
    $email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
    $message = htmlspecialchars($_POST['message']);
    
    if ($name && $email && $message) {
        // Process the form data, like sending an email
        echo "Thank you for your message, $name.";
    } else {
        echo "Please fill in all the fields correctly.";
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments