pdf - Yii2 - 即时生成 Pdf 并附加到电子邮件

标签 pdf yii2 response email-attachments swiftmailer

这就是我生成pdf页面的方式

public function actionPdf(){
    Yii::$app->response->format = 'pdf';
    $this->layout = '//print';
    return $this->render('myview', []);
}

这就是我发送电子邮件的方式
$send = Yii::$app->mailer->compose('mytemplate',[])
    ->setFrom(Yii::$app->params['adminEmail'])
    ->setTo($email)
    ->setSubject($subject)
    ->send();

如何将 pdf 生成为文件并将其即时附加到我的电子邮件中?

最佳答案

邮件程序有名为 attachContent() 的方法,您可以在其中放置 pdf 文件。

PDF 应该在输出目标设置为字符串的情况下呈现,然后将其作为参数传递给 attachContent() .

样本:

Yii::$app->mail->compose()
   ->attachContent($pathToPdfFile, [
        'fileName'    => 'Name of your pdf',
        'contentType' => 'application/pdf'
   ])
   // to & subject & content of message
   ->send();

关于pdf - Yii2 - 即时生成 Pdf 并附加到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41058147/

相关文章:

javascript - PDF 在 :always 之后无法使用 css 分页符

php - 尝试运行时出现代码错误 "Class Yii not found"

yii2 - 如何在 Yii2 中的 kv-GridView 类中将 css 类添加到 <td> 标签

html - 媒体查询适用于移动设备但不适用于浏览器调整大小

javascript - 使用 fetch 获取 API 响应负载

javascript - 通过 Blob URI 在新窗口中从 PUT 获取 PDF

pdf - 开源,多语言/Unicode字体?

php - yii2 中的 createCommand() 函数返回错误值

c# - 如何在一个 WCF 请求中发送多个返回值?

ios - 与 CGContextDrawImage 相比,为什么 UIImageView 如此占用内存