/app/Http/Controllers/FormhandlerController.php
PHP | 117 lines | 69 code | 17 blank | 31 comment | 8 complexity | f05258fff61c5d3215b1a51dd4d86e34 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Support\Facades\Mail;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Input;
- use Request;
- use App\Model\ContactFormResponse;
- use App\Model\GenericBaseResponse;
- use App\Model\BaseResponse;
- use Config;
- use App\Mail\Webform;
- use Illuminate\Support\Facades\View;
- class FormhandlerController extends Controller
- {
- /**
- * Show the application dashboard.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- // Getting all post data
- $a = array();
- if (Request::ajax()) {
-
- $data = Input::all();
- $name = $data['first_name'];
- if (iconv_strlen($name) < 2) {
- $errorResponse = new ContactFormResponse('f1', Config::get('constants.form.name'));
- array_push($a, $errorResponse);
- }
- // Field Email
- $email = $data['email'];
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $errorResponse = new ContactFormResponse('f3', Config::get('constants.form.email'));
- array_push($a, $errorResponse);
- }
- // Field Category
- // Field Message
- $msg = $data['message'];
- if (iconv_strlen($msg) < 10) {
-
- $errorResponse = new ContactFormResponse('f5', Config::get('constants.form.message'));
- array_push($a, $errorResponse);
-
- }
-
- if (count($a) > 1) {
-
- //print_r($message);die;
- $response = new GenericBaseResponse(Config::get('constants.status.validation_failure'), Config::get('constants.msg.validation_failure'), $a);
- return json_encode($response);
- } else {
- // To send HTML mail, the Content-type header must be set
- $headers[] = 'MIME-Version: 1.0';
- $headers[] = 'Content-type: text/html; charset=UTF-8';
-
- // Additional headers
- $headers[] = 'To: Admin <info@divine-healthcare.uk>';
- $headers[] = 'From: Cynosure Website <'.$email.'>';
-
- if (!isset($subject) || empty($subject)) {
- $subject = Config::get('constants.form.CONTACT_WEBMAIL');
- }
- try
- {
- /*Mail::send('emails.welcome', $data, function($message)
- {
- $message->from('us@example.com', 'Laravel');
-
- $message->to('info@sydneyapps.co.uk')->cc('mlambosydney@yahoo.com');
-
- $message->attach($pathToFile);
- });*/
- /* */
-
- $emailcontent = array(
- 'subject' => $subject,
- 'msg' => $data['message'],
- //'category' => $data['category'],
- 'name' => $data['first_name'],
- 'email'=> $data['email']
- );
- /*
- Mail::send('emails.contacthtml', $emailcontent, function($message) {
- $message->to('mlambosydney@yahoo.com', 'Receiver Name');
- $message->subject('This is the subject');
- });*/
- $view = View::make('emails.contacthtml', $emailcontent)->render();
- //TODO : REMOVE THE COMMENS
- // mail('info@divine-healthcare.uk', $subject, $view, implode("\r\n", $headers));
-
- $headers[] = 'MIME-Version: 1.0';
- $headerse[] = 'Content-type: text/html; charset=iso-8859-1';
- // Additional headers
- $headerse[] = 'To: <'.$email.'>';
- $headerse[] = 'From: Divine Healthcare <no-reply@divine-healthcare.uk>';
- //mail($email, 'We received your message below.', $view, implode("\r\n", $headerse));
-
- } catch (Exception $e) {
- $response = new BaseResponse(Config::get('constants.status.success'), 'An exception occured.');
- Log::critical($e->getMessage());
- return json_encode($response);
- }
- $response = new BaseResponse(Config::get('constants.status.success'), Config::get('constants.msg.success'));
- return json_encode($response);
-
- }
- }
- }
-
- }