'PHP form does not check other inputs

I have made a contact form, however the PHP only checks for 'message' and if thats filled out all other checks are ignored. If its not filled out all other checks work as well. Can someone please help me fix my code? Thanks.

<?php
$fullName = $customerEmail =  $message = '';
$errors = array('fullName' => '', 'customerEmail' => '', 'message' => '');

if (isset($_POST['submit'])) {
    $myEmail = "xxxxxxxxxxxxx";
    $timeStamp = date("dd/M/YY HH:i:s");
    $body = "";

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

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

    if (empty($fullName)) {
        $errors['fullName'] = "Full name is required. <br>";
    } else {
        if (!preg_match("/^([a-zA-Z' ]+)$/", $fullName)) {
            $errors['fullName'] = "Your name must be a valid name.";
        }
        
    }

    if (empty($customerEmail)) {
        $errors['customerEmail'] = "An email is required. <br>";
    } else {
        if (!filter_var($customerEmail, FILTER_VALIDATE_EMAIL)) {
            $errors['customerEmail'] = "Email must be a valid email address.";
        }
    }

    if (empty($message)) {
        $errors['message'] = "A message is required.";
    } 
    
    else {
        mail($myEmail, $chosenSubject, $body);
        header("Location: public/mail_sent.php");
    }
}
?>


Solution 1:[1]

Your last else should be changed to IF, checking if any of the fields is not empty then sends the message.

if(!empty($fullName) && !empty($customerEmail) && !empty($message)) {

    mail($myEmail, $chosenSubject, $body);

    header("Location: public/mail_sent.php");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prisca Ebuka