我想获取 HTML 格式的 php 文件的内容。我将其用作 HTML 电子邮件模板,但需要用我的数据库中的动态数据填充它。
我试过了
file_get_contents('/emails/orderconfirm.php');
但这只是在服务器将其处理为 HTML 之前返回 php 代码。
我猜这真的很简单?任何想法将不胜感激。
谢谢
最佳答案
为了执行您的emails/orderconfirm.php
中的特定代码,您需要include它的内容。
包含的内容将被编译和呈现。
但是,你只要echo
这样,您需要使用 ob_start()图书馆。
这是一个用法示例:
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
编译后的内容现在存储在您的 $emailContent
变量中,您可以按照自己的方式使用它。
$email->body = $emailContent;
关于php - 从 php 文件中获取 HTML 内容,在它被处理之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954791/