I'm trying to email to an array of subscribers to a weekly newsletter. Whenever I try though, I get an error "Bad parameters to function mail()". Heres the loop I'm using to mail:

$x = 0;
$y = 1;
while ($x <= $y)
{
    mail($names[$x], "Hey", "Whats up?");
    $x++;
}

Any help would be appreciated, thanks.

Recommended Answers

All 5 Replies

Check the array. While function works fine to me. I have done it like this:

$names[] = 'name1@host.tld';
	$names[] = 'name2@host.tld';
	$names[] = 'name3@host.tld';
	
	$x = 0;
	$y = 2;
	while ($x <= $y)
	{
	    mail($names[$x], "hey", "whats up?");
	    $x++;
	}

Bye.

If you use foreach() you won't even need to bother with the indexing.

<?php
$list[] = "first";
$list[] = "second";
$list[] = "third";

foreach ($list as $entry){
  mail($entry, "Hey", "Whats up?");
}
?>

I populated the array with a loop, that read the names from a text file. I tried doing it manually, and it worked, but I cant do it that way for what I'm doing. @Ezzaral: What is foreach()? Would that help?

Also this More Simple.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.