henryoladj
4 weeks ago
170
7
Laravel

Undefined Index

Posted 4 weeks ago by henryoladj

I have a contact form with textarea

<form action="{{ route('contact-submit') }}" method="post">
                        @csrf
                        <label for="fname">Full Name</label>
                        <input type="text" id="fname" name="name" placeholder="Your Fullname..">

                        <label for="lname">Email</label>
                        <input type="email" id="lname" name="email" placeholder="Your Email..">

                        <label for="lname">Subject</label>
                        <input type="text" id="lname" name="subject" placeholder="Your Subject..">

                        <label for="subject">Message</label>
                        <textarea id="subject" name="body" placeholder="Write something.." style="height:200px"></textarea>

                        <input type="submit" value="Submit">
                    </form>

My Controller

public function contact(Request $request)
    {
        if($request->isMethod('post')){
            $data = $request->all();

            //Send Mail
            $email = "[email protected]";
            $messageData = [
                            'name'=>$data['name'], 
                            'email'=>$data['email'],
                            'subject'=>$data['subject'],
                            'body'=>$data['body']
                        ];
                        Mail::send('emails.enquiry', $messageData, function($message)use($email){
                            $message->to($email)->subject('Enquiry from Naijaswfit');
                        });

                        return redirect()->back()->with('flash_message_success', 'Thanks for Your message.');
        }
    }

and i am getting this error Undefined index: body when i click on submit

Please sign in or create an account to participate in this conversation.