In Magento, while submit form from frontend in controller using post method i got every data. I want create one pdf file and keep this data in it after that attachment of this file and send with mail.

Thanks in advance.

2 Answers 2


Use TCPDF file for generate PDF.

How to use TCPDF in magento Go Here

Create one custom phtml file in your theme direactory and generate output to print it in tcpdf.

call it in you controller file like this

$htmlContent = $this->getLayout()->createBlock('core/template')->setPostData($data)->setTemplate('<your template file>');

and in your template file you can get your post data like


attached generated pdf with mail.


generate pdf in the media directory with post data and send it using below code.

change code according to your variable and need.

        $mailer = Mage::getModel('core/email_template_mailer');

    $emailInfo = Mage::getModel('core/email_info');
    $emailInfo->addTo($to, $customerName);

    $mailer->setSender('[email protected]');

    $filePath = $mediaDir.DS.$uploadedfilePath;
    $_pdfSavePath = Mage::getBaseDir('media').DS.'pdf_order_template';
         $pdfContent  = file_get_contents($filePath);
        $mailer->addPDFAttachment($pdfContent,  'Order_PDF-' . $order->getIncrementId() .  '.pdf');

  • Have you any example of that ? i want to add post data into pdf file and send it with mail using controller. Commented Oct 15, 2018 at 10:03
  • code added for mail with attachement
    – Zahirabbas
    Commented Oct 15, 2018 at 10:17
  • Please check new answer. Commented Oct 15, 2018 at 11:57

Please check this code:

public function sendemailAction()
      $request     = $this->getRequest()->getPost();
      $mail   = Mage::getModel('core/email');           
            $content = '<h2>Personal Information</h2><br>';
            $content .= '<label>Name:</label>'.$request['name'].'<br>';
            $content .= '<label>Email:</label>'.$request['email'].'<br>';  
    require_once(Mage::getBaseDir('lib') . DS . 'TCPDF-master/examples/tcpdf_include.php');
            // set document information
            $pdf->SetTitle('TCPDF Example GJ01');
            $pdf->SetSubject('TCPDF Tutorial');
            $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

            $pdf->writeHTMLCell(0, 0, '', '', $content, 0, 1, 0, true, '', true);
            $pdf->Output('example_001.pdf', 'I');
$to = '[email protected]';

            $mail->setSubject('Review Form');
            try {

            catch (Exception $e) {
                Mage::getSingleton('core/session')->addError('Unable to send.');

but still not working for me. Got 500 error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.