hypothetical/app/Http/Controllers/ContactController.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2016-01-03 19:08:53 -05:00
<?php namespace App\Http\Controllers;
use Mail;
use App\Models\Contact;
use Illuminate\Http\Request;
2016-08-02 22:58:40 -04:00
class ContactController extends Controller {
2016-01-03 19:08:53 -05:00
public function postContactSubmit(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'message' => 'required'
]);
$name = $request['name'];
$email = $request['email'];
$message = $request['message'];
$contact = new Contact;
2016-01-03 19:08:53 -05:00
$contact->name = $name;
$contact->email = $email;
$contact->message = $message;
$contact->save();
// Send the email if the MAIL_SENDTO variable is set
2016-01-03 19:08:53 -05:00
if (env('MAIL_SENDTO') != null) {
Mail::send('email.contact', [ 'contact' => $contact ], function ($mail) use ($contact) {
$mail->from(env('MAIL_ADDRESS'), env('SITE_NAME'))
->to(env('MAIL_SENDTO'))
->subject('Contact form submission');
});
}
return 'success';
}
2016-08-02 22:58:40 -04:00
2016-01-03 19:08:53 -05:00
}