php – 在Laravel Mail 5.5中将变量传递给邮件时出错

我试图在Laravel 5.5中发送联系邮件,我阅读了文档并尝试了在那里描述的使用方法,但不起作用.这是我的代码.

这是我的表格

    <form class="send_message" action="{{url('send_mail_error_card_r')}}" method="post">
      <div class="text_Box">
        {{csrf_field()}}
        <textarea id="send_mail_error_card" name="send_mail_error_card" rows="5" cols="40" class="form-control send_mail_error_card"></textarea>
        <div class="send_button_Box">
        <button type="submit" id="send_message" class="btn btn-default">Enviar <span class="glyphicon glyphicon-send"></span></button>
        </div>
      </div>
    </form>

我的路线

Route::post('/send_mail_error_card_r', 'HomeController@send_mail_error_card_r');

我的控制器

public function send_mail_error_card_r(Request $request)
{   $email = 'viniciusdemourarosa@gmail.com';
    $data['text'] = $request->send_mail_error_card;
    Mail::send('mail.contact', $data, function($message) use ($email){
      $message->from('vinicius.rosa@bolder.com.br', 'Contabileads Developer');
      $message->to($email);
      $message->subject("Atenção!");
    });
}

我的邮件查看

<!DOCTYPE html>
<html>
  <body>
    {{$data['text']}}
  </body>
</html>

我的邮件联系人

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

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('mail.contact')->with(['data', $this->data]);
}

关于邮件的配置

在config / mail.PHP

'driver' => env('MAIL_DRIVER', 'mailgun'),

在config / services.PHP

'mailgun' => [
    'domain' => 'secret',
    'secret' => 'secret',
],

在.ENV文件

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=secret
MAIL_PASSWORD=secret
MAIL_ENCRYPTION=ssl

我的代码返回

ErrorException (E_ERROR)
Undefined variable: data (View: /var/www/html/planos/resources/views/mail/contact.blade.PHP)

有什么建议吗?提前致谢!

解决方法:

data属性必须是公共的:

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

the docs开始:

Typically, you will want to pass some data to your view that you can utilize when rendering the email’s HTML. There are two ways you may make data available to your view. First, any public property defined on your mailable class will automatically be made available to the view

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...