生成PDF(TCPDF)并发送联系表格7

时间:2019-05-16 05:46:03

标签: php wordpress

我想从我的wordpress网站发送一封带有联系表7的电子邮件,如果要发送,我想运行一个函数,该函数生成带有TCPDF的PDF文件并将该文件附加到电子邮件。

PDF本身需要10秒钟才能生成。

该函数和表单本身可以很好地工作,但是如果我添加代码以运行generateThePDF函数并提交表单,我将仅在“提交”按钮旁边看到“加载旋转”,而没有任何反应。

如果我手动将路径设置为现有pdf文件,则效果很好。 也许生成时间太长了?

这是来自functions.php的wordpress动作钩子:

add_action('wpcf7_before_send_mail','send_pdf');
function send_pdf( $cf7 ) {

    include_once('/web/pdf/view/my-functions.php');

    $id = $cf7->id();
    $submission = WPCF7_Submission::get_instance();

    if ($submission)
    {
        // will start generating pdf and receive the filename and store it to var
        $generatedPDF = generateThePDF();
        $submission->add_uploaded_file('pdf', $generatedPDF);
    }

}

现在,我的“ my-functions.php”带有tcpdf代码:

function generateThePDF(){

    // create new PDF document
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

    ... lot of code ...

    // generate pdf and return path if finished
    $file = '/web/pdf/view/output/pdf_'.time().'.pdf';
    $pdf->Output($file, 'F');
    return $file;

}

在浏览器控制台中,等待3秒后,我会发现这个问题:

XHR完成加载:POST“ .... com / wp-json / contact-form-7 / v1 / contact-forms / 4629 / feedback”。

我不知道这对我的问题是否重要。

非常感谢您。

0 个答案:

没有答案