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'
|
|
|
|
]);
|
|
|
|
|
2016-01-26 23:20:08 -05:00
|
|
|
$contact = new Contact;
|
2017-02-06 23:44:07 -05:00
|
|
|
$contact->name = $request['name'];
|
|
|
|
$contact->email = $request['email'];
|
|
|
|
$contact->message = $request['message'];
|
2016-01-03 19:08:53 -05:00
|
|
|
$contact->save();
|
|
|
|
|
2016-08-05 14:19:17 -04:00
|
|
|
// Send the email if the MAIL_SENDTO variable is set
|
2016-01-03 19:08:53 -05:00
|
|
|
if (env('MAIL_SENDTO') != null) {
|
2016-08-05 14:41:02 -04:00
|
|
|
Mail::send('email.contact', [ 'contact' => $contact ], function($mail) use ($contact) {
|
2017-09-26 11:42:00 -04:00
|
|
|
$mail->from(env('MAIL_SENDFROM'), env('APP_NAME'))
|
2016-01-03 19:08:53 -05:00
|
|
|
->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
|
|
|
}
|