Laravel 7 上 Mailtrap 的值空值偏移问题
Offset on value null issue for Mailtrap on Laravel 7
我正在使用 Laravel 7 和 PHP 7.4.
我正在使用 Mailtrap 来测试电子邮件。我刚刚将我的 Laravel 版本升级到 7.4,我的电子邮件已停止工作。当我尝试发送演示电子邮件时,出现以下错误
Trying to access array offset on value of type null
问题在这里:
{{ $mailData['title'] }}
控制器:
class MailController extends Controller {
public function sendEmail() {
$email = 'positronx@gmail.com';
$mailData = [
'title' => 'Demo Email',
'url' => 'https://www.positronx.io'
];
Mail::to($email)->send(new EmailDemo($mailData));
return response()->json([
'message' => 'Email has been sent.'
], Response::HTTP_OK);
}
}
邮件文件:
class EmailDemo extends Mailable
{
use Queueable, SerializesModels;
public $mailData;
public function __construct()
{ }
public function build()
{
return $this->markdown('email.demoEmail')
->with('mailData', $this->mailData);
}
}
Blade:
@component('mail::message')
{{ $mailData['title'] }}
The body of your message.
@component('mail::button', ['url' => $mailData['url']])
Button Text
@endcomponent
Thanks,<br>
{{ config('app.name') }}
@endcomponent
您忘记在 constructor()
中设置 $mailData,将其传递给构造函数并将其设置为 $this->maildata
。
class EmailDemo extends Mailable
{
use Queueable, SerializesModels;
public $mailData;
public function __construct($mailData)
{
$this->mailData = $mailData;
}
}
您还没有在邮件通知 class 中初始化 $mailData
。您可以按以下方式进行:
class EmailDemo extends Mailable
{
//your other code
public $mailData;
public function __construct($mailData)
{
$this->mailData = $mailData;
}
}
希望它现在可以正常工作。
我正在使用 Laravel 7 和 PHP 7.4.
我正在使用 Mailtrap 来测试电子邮件。我刚刚将我的 Laravel 版本升级到 7.4,我的电子邮件已停止工作。当我尝试发送演示电子邮件时,出现以下错误
Trying to access array offset on value of type null
问题在这里:
{{ $mailData['title'] }}
控制器:
class MailController extends Controller {
public function sendEmail() {
$email = 'positronx@gmail.com';
$mailData = [
'title' => 'Demo Email',
'url' => 'https://www.positronx.io'
];
Mail::to($email)->send(new EmailDemo($mailData));
return response()->json([
'message' => 'Email has been sent.'
], Response::HTTP_OK);
}
}
邮件文件:
class EmailDemo extends Mailable
{
use Queueable, SerializesModels;
public $mailData;
public function __construct()
{ }
public function build()
{
return $this->markdown('email.demoEmail')
->with('mailData', $this->mailData);
}
}
Blade:
@component('mail::message')
{{ $mailData['title'] }}
The body of your message.
@component('mail::button', ['url' => $mailData['url']])
Button Text
@endcomponent
Thanks,<br>
{{ config('app.name') }}
@endcomponent
您忘记在 constructor()
中设置 $mailData,将其传递给构造函数并将其设置为 $this->maildata
。
class EmailDemo extends Mailable
{
use Queueable, SerializesModels;
public $mailData;
public function __construct($mailData)
{
$this->mailData = $mailData;
}
}
您还没有在邮件通知 class 中初始化 $mailData
。您可以按以下方式进行:
class EmailDemo extends Mailable
{
//your other code
public $mailData;
public function __construct($mailData)
{
$this->mailData = $mailData;
}
}
希望它现在可以正常工作。