这就是我生成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/