2020-04-27 06:28:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use GuzzleHttp;
|
2020-05-02 19:18:56 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2020-04-27 06:28:00 +00:00
|
|
|
|
|
|
|
class ContactController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function create(Request $request)
|
|
|
|
{
|
|
|
|
$name = $request->name;
|
|
|
|
$email = $request->email;
|
|
|
|
$subject = $request->subject;
|
|
|
|
$msg = $request->msg;
|
|
|
|
|
|
|
|
$challenge = $request->input('captcha');
|
|
|
|
|
2020-05-02 19:18:56 +00:00
|
|
|
$verifyrequest = Http::asForm()->post(config('recaptcha.verify.apiurl'), [
|
|
|
|
'secret' => config('recaptcha.keys.secret'),
|
|
|
|
'response' => $challenge,
|
|
|
|
'remoteip' => $_SERVER['REMOTE_ADDR']
|
2020-04-27 06:28:00 +00:00
|
|
|
]);
|
2020-05-02 19:18:56 +00:00
|
|
|
|
2020-04-27 06:28:00 +00:00
|
|
|
$response = json_decode($verifyrequest->getBody(), true);
|
|
|
|
|
|
|
|
if (!$response['success'])
|
|
|
|
{
|
|
|
|
$request->session()->flash('error', 'Beep beep boop... Robot? Submission failed.');
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Send mail
|
|
|
|
|
|
|
|
$request->session()->flash('success', 'Message sent successfully! We usually respond within 48 hours.');
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|