my modified php mail function doesn't work

I have a website with a contact form and it the form sends the data to my .php file via POST method. I tried a very simple script from a tutorial and it works perfectly fine. So my host doesn't seem to be a problem. But as soon as I modified the basic script and put in my own variables it stopped working. It doesn't show any syntax error and the 'name' properties from the .html file are all correct.

<?php
    if (isset($_POST['sendbtn'])) {
        $to = "[email protected]";
        $name = $_POST['Name'];
        $unternehmen = $_POST['Unternehmen'];
        $strasse = $_POST['Strasse'];
        $hausnummer = $_POST['Hausnummer'];
        $postleitzahl = $_POST['Postleitzahl'];
        $ort = $_POST['Ort'];
        $email = $_POST['Email'];
        $telefonnummer = $_POST['Telefonnummer'];
        $nachricht = $_POST['Nachricht'];
        $einverstaendniserklaerung = $_POST['Einverstaendiserklaerung'];
        $subject = "Das Kontaktformular wurde ausgefüllt";
        $email_body = "Neue Nachricht:\n";

        $email_body .= "Name: $name\n";
        $email_body .= "Unternehmen: $unternehmen\n";
        $email_body .= "Strasse: $strasse\n";
        $email_body .= "Hausnummer: $hausnummer\n";
        $email_body .= "Postleitzahl: $postleitzahl\n";
        $email_body .= "Ort: $ort\n";
        $email_body .= "E-Mail: $email\n";
        $email_body .= "Telefonnummer: $telefonnummer\n";
        $email_body .= "Nachricht: $nachricht\n";
        $email_body .= "Einverstaendniserklaerung: 
                        $einverstaendniserklaerung\n";

        mail($to, $subject, $email_body);
        header("Location: kontakt.html?mailsend");
    }
?>

This here is the working tutorial snippet:

<?php

   if (isset($_POST['sendbtn1'])) {
      $firstName = $_POST['firstName'];
      $lastName = $_POST['lastName'];
      $userName = $_POST['userName'];

      $mailTo = "[email protected]";
      $headers = "From: ".$userName;
      $txt = "Cheese: ".$firstName." ".$lastName."\n\n Ham";

      mail($mailTo, $headers, $txt);
      header("Location: index.html?mailsend");
   }
728x90

0 Answers my modified php mail function doesn't work