I'm trying to display a simple confirmation message after a PHP contact form has sent an e-mail and redirected to the previous page. I'm redirecting like so:
header("Location: contact.php?mailsend");
In the contact.php I'm trying to display the confirmation this way:
<?php
$mailsend = $_GET['mailsend'];
if ($mailsend == 1){
echo "<div><p>Your e-mail was sent.</p></div>";
}
?>
But the page only loads properly if mailsend
is present in the URL. When it is not, the page doesn't load (it shows my CMS' error page).
What am I doing wrong?
UPDATE
Wrapping my php in an isset statement, as suggested in the comments:
<?php
if (isset($_GET['mailsend'])) {
$mailsend = $_GET['mailsend'];
if ($mailsend == 1){
echo "<div><p>Your e-mail was sent.</p></div>";
}
}
?>
The page no longer throws an error, but also never displays the confirmation, even if the URL is contains mailsend=1