1

I would link to send .odt file generated by TinyButStrong using Swiftmailer. This is mu current code

->setSubject('Customer General Email from '. $date->format("m-d-Y H:i"))
            //->setTo($address)
            ->setFrom('avangardauto33@gmail.com')
            ->attach(
                \Swift_Attachment::newInstance()
                    ->setFilename('space_calculator_results.odt')
                    ->setContentType('application/odt')
                    //->setBody($TBS->Show(OPENTBS_DOWNLOAD, 'space_calc_results.odt'))
                    ->setBody($TBS->Show())
            )
            ->setBody($this->renderView(
                'WinslowUserBundle:User:calc_results_email.html.twig',
                array('data' => $data)), 'text/html');
        $this->get('mailer')->send($message);

I've got the file attached, but I can't open the file with LibreOffice.

So is there any way to get correct file handler to be able to attache it to my email later? Any help is appreciated. Thanks

Skrol29
  • 5,402
  • 1
  • 20
  • 25
Sergei Kutanov
  • 825
  • 6
  • 13
  • Could you be a little more specific please? What does *"I can't open the with LibreOffice"* mean? What **error** message do you get? Does the downloaded file contain the content generated by `$tbs->show()`? – Nicolai Fröhlich Apr 03 '14 at 17:12
  • It seems like the file has the right content. The error says "version incompobility. Incorrect file version" – Sergei Kutanov Apr 03 '14 at 18:14

1 Answers1

3

Method TBS->Show() does not return the binary result of the merge.

According to the manual, you have to do this in order to retrieve the binary content:

$TBS->Show(OPENTBS_STRING);
$string = $TBS->Source; 

So your code could be like this:

$TBS->Show(OPENTBS_STRING);

->setSubject('Customer General Email from '. $date->format("m-d-Y H:i"))
            ->setFrom('avangardauto33@gmail.com')
            ->attach(
                \Swift_Attachment::newInstance()
                    ->setFilename('space_calculator_results.odt')
                    ->setContentType('application/odt')
                    ->setBody($TBS->Source)
            )
            ->setBody($this->renderView(
                'WinslowUserBundle:User:calc_results_email.html.twig',
                array('data' => $data)), 'text/html');
        $this->get('mailer')->send($message);
Skrol29
  • 5,402
  • 1
  • 20
  • 25