Ann*_*nna 3 pdf response swiftmailer email-attachments yii2
这就是我如何生成pdf页面
public function actionPdf(){
Yii::$app->response->format = 'pdf';
$this->layout = '//print';
return $this->render('myview', []);
}
Run Code Online (Sandbox Code Playgroud)
这就是我发送电子邮件的方式
$send = Yii::$app->mailer->compose('mytemplate',[])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($email)
->setSubject($subject)
->send();
Run Code Online (Sandbox Code Playgroud)
如何将pdf生成为文件并将其附加到我的电子邮件中?
Mailer有方法调用attachContent(),你可以放pdf文件.
PDF应该在输出目标设置为字符串的情况下呈现,然后将其作为参数传递给attachContent().
样品:
Yii::$app->mail->compose()
->attachContent($pathToPdfFile, [
'fileName' => 'Name of your pdf',
'contentType' => 'application/pdf'
])
// to & subject & content of message
->send();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3050 次 |
| 最近记录: |