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 java 判断某个数 区间是否存在
  • ¥15 appium控制多个雷电模拟器问题
  • ¥15 C# iMobileDevice
  • ¥15 谁会做这个啊#ensp#Boson NetSim
  • ¥15 如何编写针对TPS6503320FRGE型号的电源管理芯片的编程代码?
  • ¥15 设计简单目录管理系统,要满足以下内容
  • ¥15 关于九十度混合耦合器信号分析问题
  • ¥15 Cesm如何关闭不用的模块呢
  • ¥15 vue2两层数据导出为excle
  • ¥15 有人能帮我做一下这个项目吗