PHP Server Side Validation failing

Right, so I have some server-side code which compliments my form, with a form file test-contact.php

The form itself works as it should, and the code is separate from the HTML document with which the form is situated. This is actioned simply from the action = "test-contact.php"

I also have required in all the input fields and the textarea field. However, as we all well know, you can type url/test-contact.php into your web browser and it will send the form and bypass the required attributes to your form fields. (Well, unless you’re using my server apparently – which can evidently pick and choose which code it wants to read and ignore the rest)

However, despite integrating the validation code – which checks for empty fields – as sourced from W3Schools, can anyone shed any light as to why my server is choosing to ignore my server-side validation code and is blatantly just sending blank messages anyway?

<?php

require_once 'sendgrid/config.php';
require 'sendgrid/vendor/autoload.php'; 

    $first = $surname = $customeremail = $company = $message = "";
    $nameErr = $surnameErr = $emailErr = $companyErr = $companyErr = $messsageErr = "";

    if ($_SERVER["REQUEST_METHOD"] == "POST") {

        if (empty($_POST["first"])) {

            $nameErr = "Name is required";

        } else {

            $first = test_input($_POST["first"]);

        }
        
        if (empty($_POST["surname"])) {

            $surnameErr = "Name is required";

        } else {

            $surname = test_input($_POST["surname"]);

        }
        
        if (empty($_POST["email"])) {

            $emailErr = "Name is required";

        } else {

            $customeremail = test_input($_POST["email"]);

        }
        
        if (empty($_POST["company"])) {

            $companyErr = "Name is required";

        } else {

            $company = test_input($_POST["company"]);

        }
        
        if (empty($_POST["message"])) {

            $messageErr = "Name is required";

        } else {

            $message = test_input($_POST["message"]);

        }

    }
    
    $email          =   new SendGridMailMail();

    $email->setFrom(FROM_EMAIL, $first." ".$surname);
    $email->setSubject(SUBJECT);
    $email->addTo("<TO EMAIL>", "Helpdesk");
    $email->addContent("text/plain", "Client Name: ".$first." ".$surname."nClient Company: ".$company."nClient Email: ".$customeremail."nClient Message: ".$message."nn");

    $sendgrid = new SendGrid(SENDGRID_API_KEY);

    try {
        $response = $sendgrid->send($email);
        //print $response->statusCode() . "n";
        //print_r($response->headers());
        //print $response->body() . "n";
        header('Location: <thankyou page>');
        
        $email  =   new SendGridMailMail();
        
        $email->setFrom(FROM_EMAIL, "Name");
        $email->setSubject("Service Support");
        $email->addTo($customeremail, $first." ".$surname);
        $email->addContent("text/plain", "Hello ".$first."nnThank you for your message. We will aim to get back to you within five working days. In the meantime, you can read how we collect, process and store your data by visiting our legal section at <redacted url>The message has been send from an unmonitored email address, so please do not reply to this email.nnThank you for contacting Blauwe Stad TechnologieënnnThe Technical Development Team.nn");
        
        $sendgrid = new SendGrid(SENDGRID_API_KEY);
        $response = $sendgrid->send($email);
        
    } catch (Exception $e) {
        echo 'Caught exception: '. $e->getMessage() ."n";
    }
  
  <html>
  
  <form action="test-contact.php" method="POST" enctype="multipart/form-data">
            <input required value="" type="text" name="first"><br/><br/>
            <input required value="" type="text" name="surname"><br/><br/>
            <input required value="" type="email" name="email"><br/><br/>
            <input required value="" type="company" name="company"><br/><br/>
            <textarea required name="message"></textarea><br/><br/>
            <button type="submit" value="Send Message">Send message</button>
    </form>
  
  </html>