加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 21:56:28 所属栏目:PHP教程 来源:网络整理
导读:这就是我如何生成pdf页面 public function actionPdf(){ Yii::$app-response-format = 'pdf'; $this-layout = '//print'; return $this-render('myview',[]);} 这就是我发送电子邮件的方式 $send = Yii::$app-mailer-compose('mytemplate',[]) -setFrom(Yii:
这就是我如何生成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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读