title: Sending HTML Email via PHP with Variables and External HTML Template
body: <p>I'm trying to send an email through PHP. Originally my $message variable was set to html as well as PHP variables from user input. This works fine--I'm receiving the emails with the correct variables and all.</p>
  
  <p>Then I tried to include some logic which checks to see which service was selected by the user from the form they filled out, and based on that, the contents of the $message variable were changed (i.e. the outputting html content was slightly different). </p>
  
  <p>In order not to have a long file with bunch of html, I decided to move the html code to separate files and set the $message variable = to file_get_contents() . The email sends fine, but my variables are no longer displaying the user input data. I even tried using session_start() at the top of the file where the html template is.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  session_start();
  
  $_SESSION["service"] = $_POST['service'];
  
  if (isset($_POST['submit'])){
    $service = $_POST['service'];
    
    if($_POST['service']=="Service 1"){$message = 'email_template-service-1.php';}
      else $message = file_get_contents("email_template-service-2.php");
  
      $to = 'email@example.com';
      $subject = 'Subject';
      $headers = 'From: webmaster@example.com' . "\r\n" .
      'Reply-To: webmaster@example.com' . "\r\n" .
  
      mail($to, $subject, $message, $headers);
      header('Location: /confirmation.php');
  }
  
  else {header('Location: /index.php');}
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Am I missing something here? TIA!</p>