I have a template that is written in twig which I’m trying to send as an email, but I’m finding that the PDF sends the content as the twig content.
$content = $this->renderPartial(Yii::getAlias('@twigrelative') . '/screen.twig', ['model' => $var, 'site' => 20]); $doc->WriteHTML($content, 2); $pdf = $doc->Output('this is ignored', \Mpdf\Output\Destination::STRING_RETURN); $user = User::find()->where(['username' => $this->email ])->one(); $mail = Yii::$app->mailer->compose() ->setFrom($user->username) ->setTo("email@example.com") ->setSubject("stuff") ->attachContent($pdf, ['fileName' => 'report.pdf', 'contentType' => 'application/pdf']);
Am I missing anything here or can I not use twig to render a PDF as an attachment? Because it works in the browser fine, because it uses a View object.