包含PHP中其他文件的文本

时间:2017-09-10 17:09:38

标签: php html

我想为我的网站创建电子邮件模板。

我的模板

所以我想说这是我的template_header.php

<html>
    <head>
        <title>
            '.$email_subject.'
        </title>
    </head>
    <body>

这是我的template_footer.php

    </body>
</html>

问题

据我所知,我可以使用输出缓冲来包含这些模板。 这是我的代码:

<?php
ob_start();
include "template_header.php";
?>
<p>Text</p>
<?php
include "template_footer.php";
$message = ob_get_contents();
ob_end_clean();
?>

但它不起作用! $message是空的!即使我做var_export($message),我什么也得不到!甚至不是一个空字符串。

  • 那么我的代码有什么问题?
  • 我可以将其他文字包括在内的其他方式是什么?

1 个答案:

答案 0 :(得分:0)

这对我有用。

ob_start(); 
//print all the things - and I mean print. echoing and plain html work.
$message = ob_get_clean();

echo $message;