0

I know this question has been asked over and over again, but I'm just not finding the answer. When I fill in the form everything works fine and the message is sent to my email adress,, however after pressing 'submit' the current page remains visible whereas I would like to ddisplay a success message on a seperate page - called succesStarter.php. Hense the header("Location:succesStarter.php"); But nothing happens?

<?php


$name_error = $email_error = "";
$name = $email = $succes = "";

if ($_SERVER["REQUEST_METHOD"] == "POST"){
    
    if(empty($_POST["name"])){
        $name_error = "Naam is vereist";
    } else {
        $name = test_input($_POST["name"]);
    }
    
    if(empty($_POST["email"])){
        $email_error = "Een emailadres is vereist";
    } else {
        $email = test_input($_POST["email"]);
        if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
            $email_error = "Dit is een ongeldig emailadres";
        }
    }
    
    if(!empty($_POST["bedrijfsadres"])) {
        return;
    } else {
        $bedrijfsadres = "";
    }
    
    $logowaarde = $_POST["logo"];
    
    if($name_error == '' and $email_error == ''){
        $message_body = '';
        unset($_POST['submit']);
        foreach ($_POST as $key => $value){
            $message_body .= "$key: $value\n";
        }
        
        $to = 'bevescontact@equinoxwebdesign.be';
        $subject = 'Contactformulier';
        if (mail($to, $subject, $message_body)) {
            /*$succes = "Bericht verstuurd. Van harte bedankt.";*/
            header("Location:succesStarter.php");
            $name = $email = '';
        }

        
    }
}

function test_input($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
  • After sending a `Location` header, it's usually a good idea to `exit;` – Phil Apr 29 '21 at 23:59
  • Thanks Phil. Made a really stupid (as always) mistake. After staring at the php code for ages I forgot to check the html - still had action="= $_SERVER[ 'PHP_SELF' ]?>" – Henk Goethals Apr 30 '21 at 15:20

0 Answers0