MyBB Community Forums

Full Version: PHPMail() Foreach using an email array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
$emails = "email1$email.com
[email protected]
[email protected]";

$emailgroup = explode("/n",$emails);
This code generates an array using each of those emails. Now how can I make it so that it generates a PHPMail() code for EACH email as a to-email?

Thanks, I don't understand foreach at all <.<
foreach($emailgroup as $email)
{
	//do something with $email as the current email in the loop
}
(2009-11-28, 07:46 PM)MattRogowski Wrote: [ -> ]
foreach($emailgroup as $email)
{
	//do something with $email as the current email in the loop
}
So like this?

$from = "[email protected]";
$emails = "[email protected]
[email protected]
[email protected]";

$emailgroup = explode("/n",$emails);
foreach($emailgroup as $email)
{
mail($email,"Subject","Hello!","From: $from") 
}
Yeah, however change:

$emails = "[email protected]
[email protected]
[email protected]";

$emailgroup = explode("/n",$emails);

to:

$emailgroup = array("[email protected]", "[email protected]", "[email protected]");

It isn't an array otherwise and then you don't need to explode.
(2009-11-28, 07:52 PM)MattRogowski Wrote: [ -> ]Yeah, however change:

$emails = "[email protected]
[email protected]
[email protected]";

$emailgroup = explode("/n",$emails);

to:

$emailgroup = array("[email protected]", "[email protected]", "[email protected]");

It isn't an array otherwise and then you don't need to explode.
This doesn't apply in my case because I'm taking the emails out of a form. But thanks Smile