Laravel:尝试发送电子邮件时无法访问空属性

时间:2018-11-20 19:14:33

标签: php laravel email

我正在尝试使用laravel发送电子邮件,但是每次运行代码时,我总是收到cannot access empty property错误。
我已经对错误进行了研究,它通常是由于在属性名称前使用$,例如$this->$username而不是$this->username引起的。但是,在我的代码中情况并非如此。

我真的不能说出是什么原因,也没有在Laravel上有丰富的经验 这是我的可邮寄课程:

<?php

namespace App\Mail;

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

class VerificationMail extends Mailable
{
    use Queueable, SerializesModels;
    public $data;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $data2 = ['companyName' => $this->data['name'], 'verificationCode' => $this->data['verificationCode']];
        return $this->from('noreply@REMOVED.com')
               ->$this->view('emails.verification', $data2);
    }
}

我的视图保存在resources / views / emails / verification.blade.php
中 我还看到有时会由于在视图中使用$message作为变量名而导致此错误,但是我不是这种情况。我尝试使用正常路由加载视图,而没有涉及任何邮件发送,并且加载正常。
 谁能发现它?谢谢。

1 个答案:

答案 0 :(得分:1)

您在这里有错误:

readMaybe

请改用以下内容:(删除第二个return $this->from('noreply@REMOVED.com') ->$this->view('emails.verification', $data2);

$this->