php - Explode a string into an array with assigned value and send the email to multiple reciepient -


i have string declared shown below

var email = 'xxx@email.com,ggg@gmail.com' 

i using explode make array

$emails = explode(",", $user->email); 

with $emails output like

array:2 [▼   0 => "xxx@email.com"   1 => "ggg@gmail.com" ] 

what expected is

$a = array('xxx@email.com'=>'abc','ggg@gmail.com'=>'cde');  result:  array:2 [▼   "xxx@email.com"=> "abc"   "ggg@gmail.com"=> "cde" ] 

i want send email multiple recipient name of recipient.e.g

abc(xxx@email.com);cde(ggg@gmail.com) 

it works fine when mail->to single recipient

mail->to('xxx@email.com','abc'); 

can tell me how can make send email multiple recipient name well?

have try using foreach ? example :

foreach($a $key=>$val) {    mail->to($key, $val); } 

update

if string have stated, maybe :

$string = "abc(xxx@email.com);cde(ggg@gmail.com)"; $data = explode(';', $string); $detailsarray = array();  foreach($data $datax){     $email = "";     //using regex filter out string paranthesis     preg_match('#\((.*?)\)#', $datax, $email);      //using str_replace remove email paranthesis name     $name = str_replace($email[0], "", $datax);      //removing paranthesis     $email[0] = str_replace(array('(',')'),'',$email[0]);      //push array     $array = array($email[0] => $name);     array_push($detailsarray,$array ); } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -