Php Laravel 8:无法发送没有发件人地址的邮件

Php Laravel 8:无法发送没有发件人地址的邮件,php,laravel,laravel-8,mailtrap,Php,Laravel,Laravel 8,Mailtrap,我想用Mailtrap和Laravel发送邮件,因此在注册后,我复制并粘贴了mail\u用户名和mail\u密码,然后我将其添加到我的控制器方法中: Mail::to('myemail@yahoo.com')->send(new TestMail('Name' , 1900)); 之后,我创建了TestMail,如下所示: class TestMail extends Mailable { use Queueable, SerializesModels; public

我想用Mailtrap和Laravel发送邮件,因此在注册后,我复制并粘贴了
mail\u用户名
mail\u密码
,然后我将其添加到我的控制器方法中:

Mail::to('myemail@yahoo.com')->send(new TestMail('Name' , 1900));
之后,我创建了
TestMail
,如下所示:

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    public $name;

    public $year;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($name , $year)
    {
        $this->name = $name;
        $this->year =  $year;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
                    ->view('emails.test')
                    ->subject('Email For testing');
    }
}
test.blade.php
只适用于:

<body>
    <h1>Website Test</h1>
    <p>Email Test</p>
    <ul>
        <li>{{ $name }}</li>
        <li>{{ $year }}</li>
    </ul>
</body>

网站测试
电子邮件测试

  • {{$name}
  • {{$year}
因此,一切看起来都很好&干净,但不知怎的,我收到了以下错误消息:

Swift_TransportException无法发送没有发件人地址的邮件

那么这里出了什么问题?如何解决此问题


如果你知道,请帮我解决这个问题,因为我真的需要它。

转到
mail.php
并将
中的
设置为如下:

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    public $name;

    public $year;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($name , $year)
    {
        $this->name = $name;
        $this->year =  $year;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
                    ->view('emails.test')
                    ->subject('Email For testing');
    }
}
'from'=>['address'=>'myname@gmail.com“,”名称“=>”我的名称“]

然后停止服务器并运行:
php-artisan-config:cache


现在重新运行服务器,它应该可以工作了…

您需要在config/mail.php中定义一个“from”地址,或者在.env中设置
mail\u from\u address
(假设您使用的是默认的config/main)。php@apokryfos它被设置为
'address'=>env('MAIL\u FROM\u address','hello@example.com),
。它错了吗?