Home > Mobile >  Contact form validation in PHP redirects to blank page
Contact form validation in PHP redirects to blank page

Time:09-26

when my form is submitted it goes to the 'action' page, however its blank. And even though I have checks for email, name etc. It does not show any errors on that blank page. Been trying to get this to work for past 2 days.

Here is my php code:

<?php

if (isset($_POST['submit']) && !empty($_POST)) {

    $myEmail = "xxxxxxxxxx"; //securyti XD
    $timeStamp = date("dd/M/YY HH:i:s");
    $body = "";

    $fullName = $_POST['fullName'];
    $customerEmail = $_POST['customerEmail'];
    $chosenSubject = $_POST['subject'];
    $message = $_POST['message'];

    $nameRegularExpression = "/^[a-zA-Z] $/";
    $emailRegularExpression = "/^\w ([\.-]?\w )*@\w ([\.-]?\w )*(\.\w{2,3}) $/";

    $body .= "From: " . $fullName . " at $timeStamp" . "\r\n";
    $body .= "Email: " . $customerEmail . "\r\n";
    $body .= "Message: " . $message . "\r\n";

    if (!preg_match($nameRegularExpression, $fullName) or empty($fullName)) {
        echo "Your name is not filled out properly or not filled out at all";
    }

    if (!preg_match($emailRegularExpression, $customerEmail) or empty($customerEmail)) {
        echo "Your mail is not valid or you forgot to fill it out";
    }

    if (empty($chosenSubject) or empty($message)) {
        echo "Dont forget to choose subject or write a message";
    }

    else {
        mail($myEmail, $chosenSubject, $body);
        header("Location: mail_sent.php");
    }
}

So I put a HTML as well hope it helps you to help me haha And this is my html:

<form action="/public/contact_form.php" method="POST">
                <label for="name">Full Name ✍           
  • Related