title: PHP Header Redirect Using Variable
body: <p>Hoping someone can help me figure out how to dynamically update a php header redirect in my mail handler file using a variable.</p>
  
  <p><strong>What I was using in my PHP mail handler:</strong></p>
  
  <pre><code>header('Location: filename.php');
  </code></pre>
  
  <p><br><strong>What I tried to do:</strong></p>
  
  <p><strong>Front End File</strong></p>
  
  <pre><code>$tyTarget = "filename.php";
  
  &lt;input type="hidden" name="redirDestination" value="&lt;?php echo $tyTarget ?&gt;" /&gt;
  </code></pre>
  
  <p><strong>PHP Mail Handler</strong></p>
  
  <pre><code>$thankYou = $_POST['redirDestination'];
  
  header('Location: $thankYou');
  </code></pre>
  
  <p><br/><br/>
  <strong>Background:</strong></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Do I just have a syntax error in my redirect?</p>
  
  <p>Any help is appreciated.  PHP noob.</p>
  
  <p><strong>Update per duplicate question flag:</strong><br>
  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.</p>