Hey Craig, it's Jon.
Only had a quick look, but you appear to be adding extra BCC headers, when actually, you only want to add additional recepients to your single BCC header. Try this...
$bcc = "";
while($r=mysql_fetch_array($sql)) {
$bcc .= $r["email"].",";
}
// remove the trailing comma
$bcc = substr($bcc, 0, -1);
$headers .= "BCC: $bcc\r\n";
Haven't checked the code, but should be fine...
Also, you may want to validate the addresses. I ran into a problem with a client sending out a mailing list to 10K addies where the addies hadn't been checked through, and several invalid addresses with spaces, or commas, had broken the script. It can get into a right mess! I went digging and came up with this...
// great email validation function that validates BOTH syntax AND existence of mx record
// Function kindly provided with permission by W. Jason Gilmore ([url]http://www.wjgilmore.com/[/url] )
// W. Jason Gilmore is an Internet application developer for the Fisher College of Business.
function validate_email($email) {
// Check first to see if we already have the addie in our mailing list
$result = mysql_query("SELECT email FROM mailing_list WHERE email = '$email'");
if(mysql_num_rows($result) < 1) {
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email)) {
list($username,$domaintld) = split("@",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
else
$valid = 0;
}
} else {
$valid = 2;
}
return $valid;
}
This function will first check the address for invalid characters, and then check that the domain is configured to receive email. It returns a different value for $valid, depending on the result. I recommend running it once on all of your addresses and using it to remove or flag any that are invalid and then just running it on any new or changed addies that are added to the list. This way, it wont bog down the server when you're sending out your mailing list. The mx validation can be a little slow!
HTH...