gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:28:58 24 4
gpt4 key购买 nike

我尝试在 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');

我的 Controller

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!");
});
}

我的邮件 View

<!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)

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

最佳答案

数据属性必须是public:

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

关于php - 在 Laravel Mail 5.5 中将变量传递给邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48341852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com