I'm trying to render a php file and then return it as html to send in an email, how would I go about doing this? Here is an example of the code that I'm using:
public function setPHP($php)
{
ob_start();
$phpsend = ( include $php );
$this->html = (string) ob_get_contents();
ob_end_clean();
}
Here is how I'm calling the function.
$php = file_get_contents( NHM_PLUGIN_DIR . 'assets/templates/newhomesguide.php' );
$css = file_get_contents( NHM_PLUGIN_DIR . 'assets/css/email_template.css' );
$cssToInlineStyles->setPHP($php);
$cssToInlineStyles->setCSS($css);
I'm trying to modify CSSToInlineStyles by Tijs Verkoyen, which inlines css with html, I'm just trying do do the same but with a php file that has functionality.
I think you're pretty close. This is how I would do it. The evaluated file will be in $this->html
like you want and it will immediately be sent to the output stream after being evaluated.
public function setPHP($php)
{
if(!file_exists($php)) // Some error handling here maybe?
die('File ' . $php . ' DNE');
// Eval the $php file and store it in a variable
ob_start();
include $php;
$this->html = ob_get_clean();
// Send the evaluated file to the output stream
echo $this->html;
}