duanliaogui4133 2016-09-13 22:56
浏览 57
已采纳

在Laravel 5.3 mailable视图中使用表单请求数据

Looking around I cant find much information on how to do this. Plenty of the same examples just explaining the basic implementation of the mailable class but thats it.

I am sending an email from a contact form and have a route set up for testing that my form posts to:

Route::post('/sendmail', function() {    
    Mail::to("my email.com")->send(new MyTestMail());
});

I then have my mailable class which I have passed a test variable as a test string to:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class MyTestMail extends Mailable
{
    use Queueable, SerializesModels;

    public $test;

    /**
    * Create a new message instance.
    *
    * @return void
    */
    public function __construct()
    {
        $this->test = "test";
    }

    /**
    * Build the message.
    *
    * @return $this
    */
    public function build()
    {
        return $this->view('emails.myTestMail');
    }
}

What I wish to do is have access to my post values from the contact from and use them in the email view.

  • 写回答

1条回答 默认 最新

  • duanfu5239 2016-09-14 00:11
    关注

    You can try passing the data you need to the constructor of that mailable.

    public $postdata;
    
    public function __construct($data)
    {
        $this->postdata = $data;
    }
    

    Now 'postdata' will be available to your view.

    Mail::to("my email.com")->send(new MyTestMail($request->all()))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了