【问题标题】:Laravel problem passing variables from controller to mailerLaravel 将变量从控制器传递到邮件程序的问题
【发布时间】:2021-04-23 19:27:10
【问题描述】:

我在将变量从控制器传递到邮件功能时遇到问题我试图在谷歌上搜索它但没有找到任何有用的东西我的目标是将变量从表单获取到welcomemail.blade 当前问题是变量没有从控制器到达我的 wlcomemail.php。邮寄部分本身确实有效。

控制器代码:

$email_data = array(
            'first_name'=>'John',
            'last_name'=>'Doe',
            'email'=>'john@doe.com',
            'password'=>'temp',
        );

        //Customer::create($data);
        Mail::to($email_data['email'])->send(new welcomemail($email_data)); 

welcomemail.php 代码:


namespace App\Mail;

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

class welcomemail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */

    public $email_data;
    public $example;

    public function __construct()
    {
        $this->email_data = $email_data;
        $this->example = 'example';
    }


    public function build()
    {
        return $this->markdown('emails.welcomemail');
    }
}

刀片代码:

# Introduction

Welcome.
{{$email_data['first_name']}}
{{$example}}
@endcomponent

【问题讨论】:

    标签: laravel email controller laravel-blade


    【解决方案1】:

    改变这个:

    public function __construct()
    {
        $this->email_data = $email_data;
        $this->example = 'example';
    }
    

    到:

    public function __construct($email_data)
    {
        $this->email_data = $email_data;
        $this->example = 'example';
    }
    

    现在你的邮件类中有它

    它应该可以工作

    【讨论】:

    • 是的,它要求帖子的发布时间约为 10 分钟
    猜你喜欢
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多