-2

i need to send emails using implode,explode and for functions

this is my code:

$ab =implode(",", $dataset['mail']); //emails
$ac =implode(",", $dataset['html']); //message
$emails[]=$ab;
$hts[]=$ac;
for($i=0;$i<count($emails);$i++)
{
  if(mail($emails[$i], $asunto, $hts[$i],$header)){
     return true;
   }

}

$ab and $ac with the implde will be like:

$ab='demo@gmail.com,demos@gmail.com,demo3@gmail.com,demo5@gmail.com';
$ac='hola,hi,gutentag';

so in for invoke mail function for each email and send too the message for each mail

how i can send it?

i need to the first mail comes with the first message and then...

Emilo
  • 35
  • 7
  • 1
    why are you imploding, setting it in a single array, and then trying to loop through that array? Why not just loop through `$dataset['mail']`? – Sean Apr 05 '15 at 21:45

1 Answers1

1

Just do this instead, no need to implode. You already have arrays.

$emails = $dataset['mail'];
$hts    = $dataset['html'];

for($i=0;$i<count($emails);$i++)
{
  if(mail($emails[$i], $asunto, $hts[$i],$header)){
     return true;
   }
}
Kosmas Papadatos
  • 1,277
  • 2
  • 14
  • 32
  • Problems here: You have 2 different arrays. This will fail whenever there is not exactly a 1:1 relation between those arrays. Better solution: Build something like a mail object that will put the mail adress and content into the object and map it like that - not split it into 2 arrays! –  Apr 05 '15 at 21:52
  • Also this will stop execution after first email is sent because of return true. – Whirlwind Apr 05 '15 at 21:53
  • the problem is ,the message is a hash excusive for each email – Emilo Apr 06 '15 at 03:28