mirror of
https://github.com/prurigro/hypothetical.git
synced 2024-11-22 07:54:11 -05:00
35 lines
1,007 B
PHP
35 lines
1,007 B
PHP
<?php namespace App\Http\Controllers;
|
|
|
|
use Mail;
|
|
use App\Models\Contact;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ContactController extends Controller {
|
|
|
|
public function postContactSubmit(Request $request)
|
|
{
|
|
$this->validate($request, [
|
|
'name' => 'required',
|
|
'email' => 'required|email',
|
|
'message' => 'required'
|
|
]);
|
|
|
|
$contact = new Contact;
|
|
$contact->name = $request['name'];
|
|
$contact->email = $request['email'];
|
|
$contact->message = $request['message'];
|
|
$contact->save();
|
|
|
|
// Send the email if the MAIL_SENDTO variable is set
|
|
if (env('MAIL_SENDTO') != null) {
|
|
Mail::send('email.contact', [ 'contact' => $contact ], function($mail) use ($contact) {
|
|
$mail->from(env('MAIL_SENDFROM'), env('APP_NAME'))
|
|
->to(env('MAIL_SENDTO'))
|
|
->subject('Contact form submission');
|
|
});
|
|
}
|
|
|
|
return 'success';
|
|
}
|
|
|
|
}
|