【发布时间】:2017-06-05 14:01:54
【问题描述】:
我在 wordpress 上使用 mpdf 来生成 PDF 文件。我正在开发一种功能,它将每周向我的用户发送报告,该报告应以电子邮件的形式发送,并且 pdf 将附加在电子邮件中。
我的问题是我在 functions.php 文件中运行代码,因为每周运行此代码,我将使用服务器端 cron 作业,我的函数应该在 functions.php 文件中执行它。所以我在functions.php文件中添加了这段代码:
function weeklyReportFunc(){
include('mpdf/mpdf.php');
$mpdf = new mPDF();
ob_start();
require get_template_directory() . '/includes/report.php';
$x = ob_get_contents();
ob_end_clean();
$mpdf->WriteHTML($x);
$today = date('Y-m-d');
$pdfName = 'weekly-report-'.$today;
$mpdf->Output($pdfName.'.pdf', 'D');
}
这向我显示了以下错误:
Warning: Cannot modify header information - headers already sent by (output started at
/home/user/public_html/doms/wp-admin/includes/template.php:1995) in /home/user/public_html/
doms/wp-content/themes/mytheme/mpdf/mpdf.php on line 8314
Warning: Cannot modify header information - headers already sent by (output started at
/home/user/public_html/doms/wp-admin/includes/template.php:1995) in
/home/user/public_html/doms/wp-content/themes/mytheme/mpdf/mpdf.php on line 1706
mPDF error: Some data has already been output to browser, can't send PDF file
我该如何解决这个问题?也许我需要在某些操作中使用我的功能?但哪一个?请问有什么想法吗?
【问题讨论】:
-
检查:/home/user/public_html/doms/wp-admin/includes/template.php:1995 通常问题是 php 文件末尾的空格(删除 php 结束标签以防止这种情况)
-
但它是 wordpress 核心文件。如果我删除 php 结束标签,那么在下一次更新时我需要重新做。在每个 wordpress 更新中都一样。 @SanderBackus
-
我检查并在那一行 (/home/user/public_html/doms/wp-admin/includes/template.php:1995) 没有奇怪的空格/结束标签,它不是甚至该文件的最后一行。有 php 关闭/打开标签,但它必须在那里。还有其他建议吗? @SanderBackus
-
那条线上还有其他输出吗?因为在发送 headers 之前应该有 0 输出。
-
这是那行内容:
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php@SanderBackus