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.
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).
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.
<?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' . "
" .
'Reply-To: webmaster@example.com' . "
" .
mail($to, $subject, $message, $headers);
header('Location: /confirmation.php');
}
else {header('Location: /index.php');}
?>
Am I missing something here? TIA!
</div>