mirror of
https://github.com/prurigro/hypothetical.git
synced 2024-11-26 17:01:25 -05:00
40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
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;
|
||
|
|
||
|
$name = $request['name'];
|
||
|
$email = $request['email'];
|
||
|
$message = $request['message'];
|
||
|
|
||
|
$contact->name = $name;
|
||
|
$contact->email = $email;
|
||
|
$contact->message = $message;
|
||
|
$contact->save();
|
||
|
|
||
|
// Send the email if this is the production environment
|
||
|
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';
|
||
|
}
|
||
|
}
|