Skip to content

Help with high school project (how to redirect a contact form) #2764

Answered by Synchro
dafaher asked this question in Q&A
Discussion options

You must be logged in to vote

Your code looks fine as far as email sending goes, though I'd recommend you learn to use composer.

To redirect after doing something, you need to send the browser a Location header telling it where to go. Importantly, you have to do this before you send any output. So replace your echo statements with lines using the [header` function](https://www.php.net/manual/en/function.header.php), and then immediately exit your script, like this:

try {
    $mail->send();
    header('Location: /email_success.php');
    exit;
} catch (Exception $e) {
    header('Location: /email_failed.php');
    exit;
}
   } else {
        echo "Hay un problema con el documento contacto.html!";
    }

where each desti…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@dafaher
Comment options

@Synchro
Comment options

@dafaher
Comment options

@dafaher
Comment options

@sandemoit
Comment options

Answer selected by dafaher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants