Hoping someone can help me figure out how to dynamically update a php header redirect in my mail handler file using a variable.
What I was using in my PHP mail handler:
header('Location: filename.php');
What I tried to do:
Front End File
$tyTarget = "filename.php";
<input type="hidden" name="redirDestination" value="<?php echo $tyTarget ?>" />
PHP Mail Handler
$thankYou = $_POST['redirDestination'];
header('Location: $thankYou');
Background:
I'm templating out a few landing pages. They use a standard HTML form that passes a couple of hidden inputs that we use internally. Historically, each landing page had its own PHP mail handler which we'd simply use a header redirect on submit to its own thank you page (i.e. thank-you-facebook.php or thank-you-email.php) which gets used for conversion tracking for each source.
Working to consolidate a bunch of these pages and use a few PHP includes to simplify the template but dynamically loading the redirect target from a variable didn't work.
Do I just have a syntax error in my redirect?
Any help is appreciated. PHP noob.
Update per duplicate question flag:
As someone who spent a while looking for answers to this question before posting, flagging this as a duplicate question because the correct answer loosely fell in line with a question regarding single quotes in PHP would not have helped me find the answer. In other words, the question was different and not a duplicate. The solution accepted as the answer just happened to be similar.