Monday, March 13, 2017

Laravel : i cant use Request object two times at the same function

Im trying to build contact form and i want it to send the user message for the website email and i want it to send message for the user mail inform him that his message received so im using that code in controller :

 public function mail(Request $request){

     Mail::send('mail.mail', ['name'=>"$request->name" , 'email'=>"$request->email" , 'msg'=>"$request->message"], function($message) {
    $message->to('housma.elma@gmail.com', 'Housma')->subject('Housma.com Enquirey');
    });



     Mail::send('mail.mailResponse', ['name'=>"$request->name"  ], function($message ) {

/*line 29 */    $message->to("$request->email", "$request->name")->subject('Housma.com : Auto reply');
    });

      return Redirect::to('/contact')->with('successful', 'Your message has been sent');
    }

the first message is for my email its working good ,but when the laravel reach the second message i get this error

ErrorException in pagesController.php line 29: Undefined variable: request



via E-housma Mardini

Advertisement