问题描述
我到处寻找这个解决方案,但似乎没有针对 PHP 8 的特定解决方案,因为我理解这个错误只是一个 PHP 错误,所以我正在尝试使用联系表格发送电子邮件,这是我的代码:
控制器:
public function _msg(Request $request,$id)
{
$info = entreprise::find($id);
//dd($info->mail);
$this->validate($request,[
'nom'=> 'required','email'=> 'required|email','telephone'=> array(
'regex:/^(?:(?:(?:\+|00)212[\s]?(?:[\s]?\(0\)[\s]?)?)|0){1}(?:5[\s.-]?[2-3]|6[\s.-]?[13-9]){1}[0-9]{1}(?:[\s.-]?\d{2}){3}$/','digits:10'
),'message'=> 'required|min:10|max:500'
]);
$information = [
'name' => $request->nom,'phone' => $request->Tel,'email' => $request->email,'message' => $request->message
];
//dd($information);
Mail::to('jon.reed10C@gmail.com')->send(new SendEmail($information));
$msg = new messages;
$msg->nom = $request->nom;
$msg->email = $request->email;
$msg->Tel = $request->Tel;
$msg->message = $request->message;
$msg->id_en = $request->id;
$msg->save();
return back()->with('success','Merci de nous contacter !');
}
可邮寄类:
class SendEmail extends Mailable
{
use Queueable,SerializesModels;
public $information;
public function __construct($information)
{
$this->info = $information;
}
public function build()
{
return $this->subject('Contact message')->view('email.msgSend');
}
}
消息视图:
<h1>Message</h1>
>>>>>>>>>> <p>Nom: {{ $information['name']}}</p>
<p>Email: {{ $information['email']}}</p>
<p>Telephone: {{ $information['phone']}}</p>
<p>Message: {{ $information['message']}}</p>
错误指向我用消息视图中的箭头指向的同一位置,我尝试转储 $information 并返回一个包含正确信息的数组,我转储了 $information['name'] 并返回了正确命名,我尝试了我找到的所有解决方案,但没有任何效果!
解决方法
您必须将 $this->info
更改为 $this->information
因为您正在为尚未声明的属性赋值。您的刀片使用定义为属性的值。您定义的属性仍然为空,因为您试图将您的值添加到不存在的属性中 :)