Ðr Ssamade
Ðr Ssamade

Reputation: 576

Php mail array to string

I need to send an email to users , everyone . and this is the array

array(5) { 
    [0]=> array(2) { ["email"]=> string(20) "[email protected]" ["name"]=> string(8) "حمزة" } 
    [1]=> array(2) { ["email"]=> string(13) "[email protected]" ["name"]=> string(4) "tooo" } 
    [2]=> array(2) { ["email"]=> string(14) "[email protected]" ["name"]=> string(8) "احمد" } 
    [3]=> array(2) { ["email"]=> string(21) "[email protected]" ["name"]=> string(14) "اشهارات" } 
    [4]=> array(2) { ["email"]=> string(20) "[email protected]" ["name"]=> string(9) 

and I have this code to send email

$hs = "From: \"Ishharat\"<[email protected]>\n";
$hs .= "Reply-To: [email protected]\n";
$hs .= "Content-Type: text/html; charset=\"utf-8\"";

 if(mail($to,$subject,$body,$hs))
   return TRUE;
 else {
   return FALSE;
 }

Upvotes: 1

Views: 145

Answers (1)

Erik Terwan
Erik Terwan

Reputation: 2780

Just use a foreach loop;

foreach ($users as $user) {
  $user->email; // the email to use in the mail() function
  $user->name; // The name to use in the headers of the mail() function
}

Upvotes: 1

Related Questions