I’ve created a simple php email script but the problem is that I dont want to include the large message text in the same php file. I want the script to read the message (exactly as it appears, with html code) from a separate html file. I’ve tried to replace the message with include("body.html"); but that unfortunately prints the html code rather than send it.
This is a small version of my script
<?php
$to .= 'email@example.com';
$subject = 'Message Subject';
$message = 'This is a very important message?';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Person Name <pname@example.com>' . "\r\n";
mail($to, $subject, $message, $headers);
?>
file_get_contents()reads the contents of a file into a string. So you could do something like this:See http://php.net/manual/en/function.file-get-contents.php for more information.
Especially if the contents of the file might be user generated, this has the advantage of there being no chance that any part of the file will be parsed as PHP and executed on your server. (There are still all the important security issues to worry about in delivering HTML to end users when you aren’t the source of the content.)