Email Yii2使用kartik\mpdf\pdf同时下载带有邮件附件的pdf

Email Yii2使用kartik\mpdf\pdf同时下载带有邮件附件的pdf,email,pdf,download,yii2,email-attachments,Email,Pdf,Download,Yii2,Email Attachments,我正在使用kartik\mpdf\Pdf库。以yii2格式生成动态数据的pdf。我可以下载文件,但我也想在邮件中发送pdf附件,同时我下载文件。谁能给我建议一个好办法吗。我的想法是首先将内容存储在变量中,然后将其发送到邮件,然后让其下载 $pdfAttachment = $pdf->render(); $message = Yii::$app->mailer->compose('attachment-template'); $message->setFrom('from@

我正在使用kartik\mpdf\Pdf库。以yii2格式生成动态数据的pdf。我可以下载文件,但我也想在邮件中发送pdf附件,同时我下载文件。谁能给我建议一个好办法吗。我的想法是首先将内容存储在变量中,然后将其发送到邮件,然后让其下载

$pdfAttachment = $pdf->render();
$message = Yii::$app->mailer->compose('attachment-template');
$message->setFrom('from@email.com');
$message->attach($pdfAttachment);
$message->setTo('sendto@gmail.com')
        ->setSubject('Message subject')
        ->send();

    return $pdfAttachment;

但这是行不通的。有人能告诉我我缺少什么吗。

你可以通过以下步骤来做到这一点:

使用参数“destination”创建pdf生成函数。 使用参数“S”调用此函数,您将以字符串形式获取pdf内容。 发送:

$email = \Yii::$app->mailer->compose()   
                           ->setTo($address)   
                           ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name])    
                           ->setSubject(' subject')   
                           ->setTextBody('...pdf attached..')   
                           ->attachContent($content,['fileName' => 'anyFilename.pdf','contentType' => 'application/pdf'])   
                           ->send();   
再次调用参数为“D”或“I”的函数。将其发送到浏览器


就这些。

还有什么错误或“不工作症状”?现在可以工作了,谢谢。我们会尽快在这里发布答案。我们仍在等待您发布答案。。。。