I have a form with database connection, form validation and mail sending.
Everything works perfectly. Only the redirection to my 'endcard.php' via headers, doesn't work no matter what i try!
Here's a snipped of the form.php. The input gets send to validation.php.
(I'm aware of the insecurity of php_self).
<?php include("includes/validation.php"); ?>
    <form name="employee"  id="employee-form" action="<?= $_SERVER['PHP_SELF'];?>"  method="POST">
      <div class="form-row justify-content-center">
        <div class="form-group col-md-5" <?= $output; ?>>
          <label for="nachname">Nachname</label>
          ......
          <input type="text" name="nachname" class="form-control" id="nachname" aria-describedby="nachnameHelp" placeholder="Geben Sie Ihren Nachnamen ein." value="<?php echo htmlspecialchars($_POST['nachname'] ?? '', ENT_QUOTES); ?>">
       <span class="error"><?php echo $nameErr?></span>
        </div>
        <div class="form-group col-md-5">
          <label for="vorname">Vorname</label>
If an error occurs, the form reloads with the error messages.( works perfectly).
Validation.php:
// define variables and set to empty values
$nameErr = $vornameErr = " ";
$nachname = $vorname   = " ";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
  if (empty($_POST["nachname"])) {
    $nameErr = "Name is required";
  } 
    else {
      $nachname = test_input($_POST["nachname"]);
      if (!preg_match("/^[a-zA-Z ]*$/", $nachname))  
             {
                $nameErr = "Only Letters and whitespace allowed";  
           }  
         } 
**// If no errors occur, include signup.php. (also works perfectly)**
 if ($nameErr == '' and $vornameErr == '') 
    {
      include('signup.php');
    }
  
signup.php will initialize the SQL query, sends the mail and should redirected to my 'endcard.php'
   //declare header
    header('Location: https://www.mywebsite/endcard.php');
     
   //declare variables and connect them to html form fields
   ... (works fine)
   //initialize sql queri
   ... (works fine)
  // sends mail
   ..(works fine)
This one doesn't work now. When submitting the form, everything above works, but I stay on the form page but should get redirected to the endcard.php.
    
// Send mail with custom headers
    if(mail($recipient, $subject, $message, $headers)) {
      require(' https://www.mywebsite.com/endcard.php');
      // I tried inlcude, didnt work either..
      // also tried to put the header in here. Also didnt work..
    }
My guess is that the action="<?= $_SERVER['PHP_SELF'];?>" doesn't allow any redirects.
But I don't know how to pass that...
Any ideas?
 
     
    