Pass variable to Mail::send() function in Laravel

Last Updated: April 24, 2018

If you need to pass variables to Mail::send() function in Laravel you can use the following code.

$data = array('email'=> $email,'subject'=>$email->subject);
             Mail::send('email.show', $data, function($message) use ($data) {
                 $message->to('receiver@gmail.com', 'Developer')->subject($data['subject']);
                 $message->from('sender@gmail.com','Admin');
            });

I have passed the subject parameter using the $data array