I want to get the contents of a php file in HTML. I am using it as a HTML email template but it needs to be populated with dynamic data from my database.
I tried
file_get_contents('/emails/orderconfirm.php');
But all that does is return the php code before it is processed by the server into HTML.
I'm guessing it's really easy? any ideas would be much appreciated.
Thanks
In order to execute the specific code in your emails/orderconfirm.php
, you need to include its content.
Included content are going to be compiled and rendered.
However, You need to get the content as long as you echo
That way, you need to use ob_start() library.
Here's an example of usage :
ob_start(); //Init the output buffering
include('emails/orderconfirm.php'); //Include (and compiles) the given file
$emailContent = ob_get_clean(); //Get the buffer and erase it
The compiled content is now stored in your $emailContent
variable and you can use it the way you want.
$email->body = $emailContent;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With