1

I want to send a pdf attachment by email. But the email content only show text "Object". My TCPDF Plugin is working, but why my script can't send email with an attachment?

Here's my script :

$mail = new Zend_Mail('utf-8');
$mail->setType(Zend_Mime::MULTIPART_RELATED);
$mail->setBodyHtml($html);
$mail->setFrom('[email protected]', 'Nekindo');
$mail->addTo('[email protected]', 'Syahidah Humairoh');
$mail->setSubject('subject');
    try {
        $mail->send();
        Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
        $this->_redirect('offer');
    }
    catch (Exception $e) {
        Mage::getSingleton('core/session')->addError('Unable to send.');
        $this->_redirect('offer');
    }

2 Answers 2

1

For that you have create attachment. First you have to put pdf in directory

$pdfName="Penawaran";
$pdf->Output(Mage::getBaseDir().'/media/tmp/'.$pdfName.'.pdf', 'F');
$pdfurl=Mage::getBaseDir().'/media/tmp/'.$pdfName.'.pdf';
     $mail->createAttachment(
                    file_get_contents($pdfurl),
                    'application/pdf',
                    Zend_Mime::DISPOSITION_ATTACHMENT,
                    Zend_Mime::ENCODING_BASE64,
                    $pdfName.'.pdf' 
                );
8
  • why the result is error page ? it says "Exception printing is disabled by default for security reasons." Commented Mar 24, 2017 at 7:17
  • check the var/log folder for error and share the error Commented Mar 24, 2017 at 7:20
  • in my error number report says Invalid method Mage_Core_Model_Email::createAttachment(Array (........... Commented Mar 24, 2017 at 7:33
  • @syahidahhumairoh check this magento.stackexchange.com/questions/9652/… Commented Mar 24, 2017 at 7:35
  • 1
    Thankyou Qaisar Commented Mar 24, 2017 at 8:05
1

You are just putting the PDF object as the text body of the email. So when the __toString method is called on the object it is just returning "Object". Instead you want to load the PDF file in to a Zend_Pdf object, render it and use that output as the attachment.

        $mail->createAttachment(
            Zend_Pdf::load($pdfFilePath)->render(),
            'application/pdf',
            Zend_Mime::DISPOSITION_ATTACHMENT,
            Zend_Mime::ENCODING_BASE64,
                      'My_Custom_Filename.pdf'
        );
2
  • the result is error page "Exception printing is disabled by default for security reasons." Commented Mar 24, 2017 at 6:02
  • So what is in the var/log/error.log or var/report/* file? There should be a report number on the error page which links to a filename in the var/report folder.
    – Brett
    Commented Mar 24, 2017 at 12:53

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.