<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;
use App\Mail\ContactFormMail;

class ContactController extends Controller
{
    public function store(Request $request)
    {
        // Validate the form
        $request->validate([
            'name' => 'required',
            'email' => 'required|email',
            'message' => 'required'
        ]);

        // Prepare data
        $data = $request->only('name', 'email', 'message');

        // Send email to your Gmail
        $mailSent = Mail::to($data['email'])->send('emails.contact', ['data' => $data],function($message) use ($data) {
            $message->message('elll')->subject('Çontact FROM')->from(env('MAIL_FROM_ADDRESS'));
        });
        if($mailSent) {
            dd($mailSent);
        }
        return back()->with('success', 'Message sent successfully!');
    }
}