当试图发送消息时,在我看来,verifyEmail.blade.php $agent是空的,$agent->name表示试图获取非对象的属性。
verifyEmail.blade.php
<body>
<h2> Welcome to our website{{ $agent->name }} </h2>
click <a href= "/user/verify/{{ $agent->verifyUser->token }}"> here </a> to verify your email
</body>我就是这样使用Mail类的。在我的邮件文件夹中的verifyEmail文件中,我有一个构造函数,它收集$agent模型。
verifyEmail.php
class verifyEmail extends Mailable
{
public $agent;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($agent)
{
$this->$agent = $agent;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.verifyEmail');
}
}在我的管理控制器中,用户注册如下所示。send方法将代理模型传递给在我观看的教程中工作的verifyEmail.php。如何使代理模型在verifyEmail.blade.php中可用
AdminController
$agent = new agent($data);
$agent->name = $data["name"];
$agent->email = $data["email"];
$agent->nrc = $data["nrc"];
$agent->resident = $data["residents"];
$agent->password = Hash::make($data["password"]);
$agent->save();
verifyUser::create(
[
'token' => Str::random(60),
'agent_id' => $agent->id,
]
);
Mail::to($agent->email)->send(new verifyEmail($agent));发布于 2021-03-31 11:50:08
我认为可以对为解决这一问题而提供的代码进行轻微的修改。
在文件verifyEmail.php中,行
$this->$agent = $agent;应该是
$this->agent = $agent;因为$this->$agent可能无法找到类级变量'agent‘并更新它在构造函数中提供的值,因此它将具有默认值null,这将在后面显示。
发布于 2021-03-31 11:43:46
配置发件人
首先使用from方法,让我们探索如何配置电子邮件的发件人。或者,换句话说,电子邮件将是“来自”谁。有两种方法可以配置发送方。首先,您可以在可邮件类的from方法中使用build方法:
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('example@example.com')
->view('emails.orders.shipped');
}但是,如果应用程序对其所有电子邮件使用相同的" from“地址,则在生成的每个可邮件类中调用from方法会变得非常麻烦。相反,您可以在config/mail.phpconfiguration file. This address will be used if no other中指定全局"from“地址,从”address“在mailable类中指定:
'from' => ['address' => 'example@example.com', 'name' => 'App Name'],此外,您还可以在config/mail.php配置文件中定义全局"reply_to“地址:
'reply_to' => ['address' => 'example@example.com', 'name' => 'App Name'],所以您可以在verifyEmail.php中尝试这个,更改这个
public function build()
{
return $this->view('emails.verifyEmail');
}到这个
public function build()
{
return $this->from('info@domain.com')->view('emails.verifyEmail');
}https://stackoverflow.com/questions/66887030
复制相似问题