text: Q:
  
  Why can't my Laravel script use variables in sending mail
  
  I'm using Laravel 4.x and have a controller script that sends email. If my recipient parameters are hard coded, the script works.
  $email_data = array('inv_no' => '12345');
  
  Mail::send('view.emailbody', $email_data, function($message) {
    $message->to('johndoe@abc.com', 'ABC Co')->subject('Invoice');
  });
  
  But if I use variables on recipient parameters, my script does not work.
  $email_data = array('inv_no' => '12345');
  $company_email = 'johndoe@abc.com';
  $company_name = 'ABC Co';
  
  Mail::send('view.emailbody', $email_data, function($message) {
    $message->to($company_email, $company_name)->subject('Invoice');
  });
  
  I really can't figure out where my error is.
  Thanks in advance
  
  A:
  
  You have to pass those variable then it will work as follows: 
  $email_data = array('inv_no' => '12345');
  $company_email = 'johndoe@abc.com';
  $company_name = 'ABC Co';
  
  Mail::send('view.emailbody', $email_data, function($message) use ($company_email, $company_name) {
    $message->to($company_email, $company_name)->subject('Invoice');
  });
  
  