【发布时间】:2021-06-26 12:46:02
【问题描述】:
我有以下邮件:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class UserLoginDetailsMail extends Mailable
{
use Queueable, SerializesModels;
protected String $username;
protected String $email;
protected String $password;
/**
* Create a new message instance.
*
* @param String $username
* @param String $email
* @param String $password
*/
public function __construct(String $username, String $email, String $password)
{
$this->username = $username;
$this->email = $email;
$this->password = $password;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->from('test@test.com', env('TENANT_NAME'))
->replyTo(env('TENANT_EMAIL'))
->to($this->email)
->subject('Test')
->view('api.emails.user-login-details')
->with([
'username' => $this->username,
'password' => $this->password,
]);
}
}
像这样被解雇:
Mail::queue(new UserLoginDetailsMail('test', "test@test.com", "test"));
但是我排队的作业遇到以下错误:
ErrorException: Trying to get property 'email' of non-object in /vendor/laravel/framework/src/Illuminate/Mail/Mailable.php:612
/**
* Set the recipients of the message.
*
* All recipients are stored internally as [['name' => ?, 'address' => ?]]
*
* @param object|array|string $address
* @param string|null $name
* @param string $property
* @return $this
*/
protected function setAddress($address, $name = null, $property = 'to')
{
foreach ($this->addressesToArray($address, $name) as $recipient) {
$recipient = $this->normalizeRecipient($recipient);
$this->{$property}[] = [
'name' => $recipient->name ?? null,
'address' => $recipient->email,
];
}
return $this;
}
这个排队的邮件正在另一个排队的作业中被触发,不确定这是否会产生任何影响。
谢谢
【问题讨论】:
-
/vendor/laravel/framework/src/Illuminate/Mail/Mailable.php第 612 行在您的版本中是什么样的?当前版本将该行作为注释,没有帮助。 -
也只是为了确认您的 ENV TENANT_NAME 和 TENANT_EMAIL 设置正确?
-
ENV 变量均设置正确。在 Laravel 版本 7 上运行
-
好的,那么第612行有什么?
-
我已更新我的问题以包含此内容。
'address' => $recipient->email,