Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何检索当前登录的电子邮件地址并在Laravel中发送邮件_Php_Laravel - Fatal编程技术网

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');
}