Php 如何检索当前登录的电子邮件地址并在Laravel中发送邮件
试试这个Php 如何检索当前登录的电子邮件地址并在Laravel中发送邮件,php,laravel,Php,Laravel,试试这个 if ($user->save()) { $data = DB::table('posts')->get(); $data = array( 'description' => $request->description, 'Location'=> $request->Location, 'lat' => $request->l
if ($user->save()) {
$data = DB::table('posts')->get();
$data = array(
'description' => $request->description,
'Location'=> $request->Location,
'lat' => $request->lat,
'lng' => $request->lng,
);
Mail::send('contact',$data,function($message) use($data) {
//Mail has been sent but both the From and To email address are same
// i.e. abc@gmail.com not Logged in user's email
$message->from(Auth::user()->email);
//to email address which i have hard coded
$message->to('abc@gmail.com');
$message->subject($data['Location']);
});
return redirect('/index');
}
}
}登录时将您的电子邮件地址放入会话中,发送时从会话中检索mail@NazmulHasan我需要当前登录的电子邮件地址,但在我看到的文档中,我们只能重试所有电子邮件地址,而不是登录用户的!!!我尝试了上面的代码@Nazul Hasan,将错误作为1/1 ErrorException未定义变量:email我对你的代码和电子邮件地址感到困惑,你能解释一下吗@纳兹穆尔·哈桑
if ($user->save()) {
$data = DB::table('posts')->get();
$data = array(
'description' => $request->description,
'Location'=> $request->Location,
'lat' => $request->lat,
'lng' => $request->lng,
);
if (Auth::check()
{
$data['email'] = User::whereId(Auth::user()->id)->value('email');
}
if(empty($data['email'])) return false;
Mail::send('contact',$data,function($message) use($data) {
//Mail has been sent but both the From and To email address are same
// i.e. abc@gmail.com not Logged in user's email
$message->from($data['email']);
//to email address which i have hard coded
$message->to($data['email']);
$message->subject($data['Location']);
});
return redirect('/index');
}