i use mailgun and the setting is done and i've test it and work, but i dont understand why i can't send email without array, here i tried using array but idk why it's error said Undefined variable: data
public function kirim(Request $request){
$data = array(
'email_address'=>$request->email_address,
'cc'=>$request->cc,
'subject'=>$request->subject,
'keterangantambahan'=>$request->keterangantambahan
);
Mail::send('laporan.kirim', $data, function($message) {
$message->from('christian7andrew@gmail.com', 'PuraBox');
$message->to($data['email_address']);
});
return redirect('/');
}
any idea how to use array corectly ??
Use a use
.
Looks like you are using a php version which supports closures
Mail::send('laporan.kirim', $data, function($message) use ($data) {
$message->from('christian7andrew@gmail.com', 'PuraBox');
$message->to($data['email_address']);
});
The second parameter of the send()
method is to set mail options . Does not place the variable inside the function body.
The use
puts variables into the body of the function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.