php - laravel variable not defined -
this weird. sure missing simple. have following code:
$producttoken = input::get('key'); $products = new product; $useremail = $products->activateproduct($producttoken); $productdetailsarray = $products->getproductdetailsforuseremail($producttoken); $emaildata = $productdetailsarray; mail::send('emails.productreleased', $emaildata, function($message){ $message->to($useremail)->subject('notification - product released public!'); });
it supposed activate product in database , send email user. email of user in $useremail , when did var_dump, shows. somehow line throws error $useremail undefined:
$message->to($useremail)->subject('notification - product released public!');
this error get:
undefined variable: useremail
i used mail function before instead of passing variable passed input::get('email') because in registration form. right now, don't have access input rather $useremail. please advise.
you using callback function @ time function called, useremail
variable out of scope. should send useremail
variable function, maybe :
mail::send('emails.productreleased', $emaildata, function($message) use ($useremail) { $message->to($useremail)->subject('notification - product released public!'); });
see http://www.php.net/manual/fr/functions.anonymous.php#example-191 information lambda (anonymous) function , context.
Comments
Post a Comment