首页 > 解决方案 > 如何将变量传递给降价?laravel 邮件

问题描述

我正在使用MailMessage将邮件消息发送到 mailtrap,并且我传递了一个变量email.

我的问题是它无法识别我在降价中传递的变量。它在下面返回错误

Facade\Ignition\Exceptions\ViewException:未定义变量:电子邮件(查看:/var/www/resources/views/ema...

有人知道传递和获取变量 from-to markdown 的正确方法是什么?


这是我的代码

return (new MailMessage)
    ->greeting('hello')
    ->line('Innerline sample')
    ->action('Reset Button', 'http://localhost:3002/reset?sample=gibor213kg')
    ->line('sample')
    ->markdown('emails.reset')
    ->with('email', 'orange@gmail.com');

这是我的降价外观

@component('mail::layout', ['email' => $emaill])

//more codes here

{{ $email }}

//more codes here

@endcomponent

标签: phplaravellaravel-mail

解决方案


将变量作为第二个参数传递。

return (new MailMessage)
    ->greeting('hello')
    ->line('Innerline sample')
    ->action('Reset Button', 'http://localhost:3002/reset?sample=gibor213kg')
    ->line('sample')
    ->markdown('emails.reset', [
        'email' => 'orange@gmail.com',
      ]);

https://laravel.com/docs/8.x/mail#markdown-mailables


推荐阅读