N
N
Nertyk2019-04-30 17:14:31
Yii
Nertyk, 2019-04-30 17:14:31

How to send two PDF files by mail?

Hello, there is a function to convert html code to pdf file and send it:

public function actionSend($id)
    {
        $model = $this->findModel($id);
        $pdf = new Pdf([
            'mode' => Pdf::MODE_UTF8, // leaner size using standard fonts
            'content' => $this->renderPartial('act.php', [
                'model' => $this->findModel($id),
            ]),
            'cssFile' => '@vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.css',
            'cssInline' => '.img-circle {border-radius: 50%;}',
            'options' => [
                'title' => 'Счёт',
                'subject' => 'Generating PDF files via yii2-mpdf extension has never been easy'
            ],
            'methods' => [
                'SetHeader' => ['Generated By: ARIANA WORLDWIDE||Generated On: ' . date("r")],
                'SetFooter' => ['|Page {PAGENO}|'],
            ]

        ]);
        //echo $this->render('act', ['model' => $model]);
        if ($id) {
            $content = $pdf->content;
            $filename = $pdf->filename;

            /*$mpdf = $pdf->getApi();
            $mpdf->WriteHtml($content);*/
            ob_clean();
            $path = $pdf->Output($content, Yii::getAlias('@root_folder') . '/frontend/uploads/' . $filename . 'Act.pdf', \Mpdf\Output\Destination::FILE);
            $sendemail = Yii::$app->mailer->compose()
                ->attach(Yii::getAlias('@root_folder') . '/frontend/uploads/' . $filename . 'Act.pdf')
                ->setFrom('[email protected]')
                ->setTo('[email protected]')
                ->setCc('[email protected]')
                ->setSubject('Счёт Alisa Market')
                ->send();
            if ($sendemail) {
                unlink(Yii::getAlias('@root_folder') . '/frontend/uploads/' . $filename . 'Act.pdf');
                return $this->render('act');
            }

        }

Now it is necessary to send two files, two different codes, but in one letter, how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-04-30
@Nertyk

Good afternoon.
Specify multiple attach()

$sendemail = Yii::$app->mailer->compose()
                ->attach(Yii::getAlias('@root_folder') . '/frontend/uploads/' . $filename . 'Act1.pdf')
                ->attach(Yii::getAlias('@root_folder') . '/frontend/uploads/' . $filename . 'Act2.pdf')
                ->attach(Yii::getAlias('@root_folder') . '/frontend/uploads/' . $filename . 'Act3.pdf')
               /* остальной код */

ps
Why create an extra alias '@root_folder'? Are the standard type aliases not enough for you @frontendor @webroot?

E
Eugene Wolf, 2019-04-30
@Wolfnsex

Take any ready-made class / library / component for sending mail from PHP, for example:
1. Swiftmailer
2. PHPMailer
3. php_libmail
As far as I remember, among other things, they allow you to attach any number of files to an e-mail letter (before sending it) .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question