Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:07:32+00:00 2026-06-12T19:07:32+00:00

I have a mail_merge function (using cakephp) which when called directly from the browser

  • 0

I have a mail_merge function (using cakephp) which when called directly from the browser e.g.
domain.com/contacts/mail_merge will generate the PDF and save it to the server as needed with the database mapped fields.

When however I try to call this mail_merge function from another function. e.g. $this->mail_merge($cond, 1); The PDF won’t generate. The database fields are still coming though to the mail_merge function so it’s not this issue. Any idea why this might be happening? I have updated my code below to now include a simple generated txt file with the code I am trying to put onto the PDF and this works so there is simply something about mPDF that won’t generate a PDF when called from a function.

Thanks

My mail_merge function is as follows:

// FUNCTION GENERATE MAIL MERGE - mPDF
// -------------------------------------------------------------->
function mail_merge($conditions=NULL, $mail_merge_id=1)
{
    // REMOVE THE STANDARD LAYOUT
    // ------------------------------------------------------>
    $this->layout = null;

    // GET THE CONTACTS
    // ------------------------------------------------------------->
    $contacts = $this->Contact->Card->find('all', array(
                                                  'limit' => 10, 
                                                  //'fields' => $fields,
                                                'contain' => array('Contact', 'Prospect', 'SaleDetail'),
                                                  'conditions' => $conditions
                                                  ));
    $this->set('contacts', $contacts);

    // GE THE CONTENTS
    // ------------------------------------------------------------>
    $this->loadModel('MailMerge');
    $content = $this->MailMerge->find('first', array(
                                                'conditions' => array('MailMerge.id' => $mail_merge_id),
                                                'fields' => array('MailMerge.description')
                                                ));
    $this->set('content', $content);

    // initializing mPDF
    // --------------------------------------------------------------------------->
    $this->Mpdf->init();

    // RENDER THE VIEW AND SET AS A VARIABLE TO WRITE THE HTML
    // --------------------------------------------------------------------------->
    $response = $this->render('mail_merge');
    $thebody = $response->body();
    $this->Mpdf->WriteHTML($thebody);

    // setting filename of output pdf file
    // --------------------------------------------------------------------------->
    $thefilename = "mail_merge_".date("d.m.Y_His").".pdf";
    $this->Mpdf->setFilename(APP. WEBROOT_DIR . "/files/csv_exports/" . $thefilename); 

    // setting output to I, D, F, S
    // --------------------------------------------------------------------------->
    $this->Mpdf->setOutput('F');

    // TEMP - CREATE TXT FILE ON THE SERVER
    // ------------------------------------------------------------------------>
    $thefilenametxt = "mail_merge_".date("d.m.Y_His").".txt";
    $ourFileHandle = fopen(APP. WEBROOT_DIR . "/files/csv_exports/" . $thefilenametxt, 'w');
    fwrite($ourFileHandle, $thebody); 
    fclose($ourFileHandle); 

    return $thefilename;

} // END MAIL MERGE
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:07:34+00:00Added an answer on June 12, 2026 at 7:07 pm

    I discovered the issue lied with the setOutput function of the component.

    When I changed:

    $this->Mpdf->setFilename(APP. WEBROOT_DIR . "/files/csv_exports/" . $thefilename); 
    $this->Mpdf->setOutput('F');
    

    To

    $this->Mpdf->Output(APP. WEBROOT_DIR . "/files/csv_exports/" . $thefilename, 'F');
    

    it worked as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using C# to generate reports in MS Word. I have a predefined
If I have a mail object, eg: mail = Mail.new do from jim@gmail.com to
I have a mail function that sends out an email with content from an
Does anyone have any experience with doing mail merge from Java on a word
I have an e-mail template which is just a plain, static HTML page. I
I have mail.py file: # coding: utf-8 from ..lib.common import * from ..lib.common import
I have a Java EE 6 application in which I'd like to use velocity
I have this wrapper to load a symfony project from within Joomla class NZGBCComponentHelper
Preferably using a scripting language like Perl or Python, but if I have to
I have an xml document that I would to parse using SSIS 2005 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.