Yii 2发送带附件的邮件

通过Yii 2框架,使用gii生成Model和CRUD操作,配置components并在web目录下创建attachments文件夹用于存储附件。在emails控制器的create方法中实现文件上传并发送带附件的邮件,邮件发送需依赖服务器支持。
摘要由CSDN通过智能技术生成

Yii 2发送带附件的邮件

首先使用gii创建下面这张表的Model和curd方法


创建成功后,在配置文件的components中添加


  
  
  
  1. 'mailer' => [
  2. 'class' => 'yii\swiftmailer\Mailer',
  3. 'viewPath' => '@common/mail',
  4. // send all mails to a file by default. You have to set
  5. // 'useFileTransport' to false and configure a transport
  6. // for the mailer to send real emails.
  7. 'useFileTransport' => true,
  8. ],

在web目录下新建attachments目录,然后把emails控制器的create方法改为

上传附件,发送邮件,即可看到发送成功(需要你服务器的支持,本地是收不到邮件的)!


  
  
  
  1. public function actionCreate()
  2. {
  3. $model = new Ema
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值