如何检索当前登录的电子邮件地址并在Laravel中发送邮件

时间:2017-07-19 13:05:41

标签: php laravel

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

1 个答案:

答案 0 :(得分:1)

试试这个

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

}