将php文件的内容导入php变量

I have an external php file like this:

<!DOCTYPE>
<head>...
...
<body>

<p><?php echo $content;?></p>
..

AND in my code:

$content = 'sample text';
$body = include("layout/mailtemplate.php");

You can see it has php and html code (and pass $content outside of file to included file)

Is there any way to store content of this file to a php variable? (here content of $body is "1"!)

Also I test

$body = file_get_contents('layout/mailtemplate.php');

It works, but I could not pass $content to file.

(I know I could pass it via GET) but I have a lot of variables. Is there a simpler way?

Yes, you can. You need to use output buffering for that:

ob_start();
$content = 'sample text';
include("inc.php");
$body = ob_get_contents();
ob_end_clean();

var_dump($body); // string(11) "sample text"