Advertisement
Guest User

kilian site.php (part)

a guest
Aug 8th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. /**
  2.  * Contact page
  3.  */
  4. Route::post('contact', function() {
  5.  
  6.     $input = Input::get(array('contact-subject', 'contact-name', 'contact-email', 'contact-message', 'contact-math'));
  7.  
  8.     // Validator check...
  9.     $validator = new Validator($input);
  10.  
  11.     $validator->check('contact-subject')
  12.         ->is_max(1, "Subject is required!");
  13.  
  14.     $validator->check('contact-name')
  15.         ->is_max(2, "Name is required!");
  16.  
  17.     $validator->check('contact-email')
  18.         ->is_email("Email is required!");
  19.  
  20.     $validator->check('contact-message')
  21.         ->is_max(5, "Message is empty or too short!");
  22.  
  23.     $validator->check('contact-math')
  24.         ->is_answer(Session::get('contact-math-session'), "Wrong math answer!!!");
  25.  
  26.     if($errors = $validator->errors()) {
  27.         Input::flash();
  28.         Notify::error($errors);
  29.         return Response::redirect('contact#error');
  30.     }
  31.  
  32.     $me = "tobias.abeling@gmx.net"; // Your email address
  33.     $subject = $input['contact-subject'];
  34.     $message = $input['contact-message'];
  35.  
  36.     $header  = "From: " . $input['contact-email'] . " \r\n";
  37.     $header .= "Reply-To: " . $input['contact-email'] . " \r\n";
  38.     $header .= "Return-Path: " . $input['contact-email'] . "\r\n";
  39.     $header .= "X-Mailer: PHP \r\n";
  40.  
  41.     if(mail($me, $subject, $message, $header)) {
  42.         Notify::success("Email sent!");
  43.         return Response::redirect('contact#sent');
  44.     } else {
  45.         Notify::error("Failed to send email!");
  46.         return Response::redirect('contact#failed');
  47.     }
  48.  
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement