The following code is the action for a contact form. The form is supposed to send mail, the mail doesn't send and the headers don't work. Instead, I get 'contact/contactForm' which is the action.
<?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    
    if(isset($_POST['submit'])){
        if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
            $firstname =$_POST['firstname'];
            $surname =$_POST['surname'];
            $email =$_POST['email'];
            $tel =$_POST['tel'];
            $service =$_POST['service'];
            $message =$_POST['message'];
        
            $mailTo = myEmail;
    
            $headers = "From: personalEmail;";
            $txt = "You have received an e-mail from ". $firstname . " " . $surname . ".\r\n" .$message . ".\r\n Contact Number:" . $tel . ".\r\n Email: " . $email;
        
            $secretKey = #;
            $responseKey = $_POST['g-recaptcha-response'];
            $userIP = $_SERVER['REMOTE_ADDR'];
            $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
        
            $response = file_get_contents($url);
            $response = json_decode($response);
            
            if($response->success){
                // echo $mailTo . " ," . $service . " ," . $txt . " ," . $headers;
                mail($mailTo, $service, $txt, $headers);
                header("Location: ../contact/?message_sent", 303);
            }
            else{
                //Failed
                header("Location: ../contact/?catchpha", 303);
            }
        }
        else{
            header("Location: ../contact/?message_failed", 303);
        };
    };
    header("Location: ../contact/?form_failed", 303);
    die(); // Stops crawlers
?>  
The mailTo, personalEmail, and secretKey are just replacements for sensitive information.
 
    