Assigning HTML contents to PHP variables

If its raw HTML, with no PHP in it, stored in separate file it would be just

$a_div = file_get_contents('email.html');

If it's PHP file with HTML mixed with PHP then include it using output buffering like in Robik's answer.

ob_start();
include 'mail.template.php';
$a_div = ob_get_contents();

But if it's relatively small, I'd use HEREDOC

$a_div = <<<HERE
<div>Contents goes <b>here</b></div>
HERE;

Try with ob_get_contents: ob_get_contents() or ob_get_clean()

<?php ob_start(); ?>
<div>Contents goes <b>here</b></div>
<?php $contents = ob_get_contents(); ?>

Tags:

Php