How to Pass Variable inside the function

Asked

Viewed 20 times

-2

In this "Laravel PHP" email sending script I loop for multiple sending.

The problem is that I’m not finding the solution to pass the variables "$email" of posts to within the function "Function($m)"

I’m only able to pass this way "define('EMAIL', $email);" but in the loop it error What’s the best way to do that?

public function disparo_em_massa(Request $campos) //contato
{

 foreach ($campos['id'] as $key => $value) {
 $contato = $_POST['contato'][$key];//
 $email = $_POST['email'][$key];// 
 $id = $_POST['id'][$key];// 



 define('EMAIL', $email);
 Mail::send('emails.recadatro_mail',[
   'id' =>$id ,
   'nome' => $contato , 
   'email' =>$email ], 

   
 function($m) {

   echo $email = EMAIL;
   $m->from('[email protected]', 'Triplxx Receptivo');
   $m->to("$email");
   $m->returnPath('[email protected]');
   $m->subject('Atualização Cadastral');
   $m->getHeaders()->addTextHeader('X-Confirm-Reading-To: [email protected]');
   });

  }

 }
  • Dude, you’re mixing Windows with raw php, the Windows has features need to access the $_POST directly. The Mail can also be sent to multiple emails at once without needing to perform foreach.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.