Hi all!
Created a form that will be submitted via email and the PHP code that was used to create the submission is generating "Mail Sent" on the page before the form is even filled out. We decided to change the code to redirect to a thank you page rather than simply displaying "Mail Sent" or "Mail send failure" when submitted. However, the code I have tried is giving me errors on the page or just not redirecting.
The following is the original code that is displaying incorrectly. Is there a simple fix to the code that would redirect properly? We would like to redirect to a thank you page when successfully submitted and an error page when failed.
<?php
[i]i deleted out all of the unnecessary part of the code that links to the form fields to save reading time[/i]
/*Sending Email*/
$to = "me@domain.com";
$subject = "New Application";
$message = "[i]also deleted all of this unneccessary info to save time[/i]"
if(mail($to, $subject, $message, "From: $from"))
echo "Mail sent";
else
echo "Mail send failure - message not sent";
?>
I tried replacing
echo "Mail sent";
else
echo "Mail send failure - message not sent";
with
echo $mail_sent ? header("Location: thankyou.php"): "Mail failed";
but that just results in "Mail failed" showing on the page instead of "Mail sent" even without anything being filled out.
Also tried
if($mail_sent) {
header('Location: thankyou.php');
exit();
}else{
echo 'Mail failed';
}
but no luck there either.
Thank you for any help in advance!
