示例#1
0
 public function postContact(Requests\StoreContactRequest $request)
 {
     $params = $request->all();
     $captchaStr = '';
     $captchaParams = ['secret' => env('CAPTCHA_SECRET'), 'response' => $params['g-recaptcha-response'], 'remoteip' => $request->getClientIp()];
     // Transform captcha array into url get params
     foreach ($captchaParams as $key => $val) {
         $captchaStr .= $key . '=' . $val . '&';
     }
     rtrim($captchaStr, '&');
     // Make a curl call to google captcha
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
     curl_setopt($curl, CURLOPT_POST, count($captchaParams));
     curl_setopt($curl, CURLOPT_POSTFIELDS, $captchaStr);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $result = json_decode(curl_exec($curl), TRUE);
     curl_close($curl);
     // If OK, send mail
     if ($result['success']) {
         Mail::send('mail.contact', ['name' => $params['name'], 'email' => $params['email'], 'tel' => $params['tel'], 'msg' => $params['message']], function ($mail) use($params) {
             $mail->to(User::find(1)->email)->subject(ucfirst(trans('front/contact.new_message_subject')));
         });
         return back()->with('message', ucfirst(trans('front/contact.success_sent')));
     } else {
         return back()->with('message', ucfirst(trans('front/contact.captcha_failed')));
     }
 }
示例#2
0
 /**
  * @param Requests\StoreContactRequest $request
  * @param ContactRequest $contact
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postContact(Requests\StoreContactRequest $request, ContactRequest $contact)
 {
     $this->contactRepository->save($request->only(['name', 'email', 'phone_number', 'message']));
     Flash::success("Contact request successfully sent.");
     return redirect()->back();
 }