tags:

views:

61

answers:

3

hay i used this code

$to       = "[email protected],[email protected]";
$subject  = "Mini-mass Emailer";
$message  = "<a href='#'>Hello World</a>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <[email protected]>' . "\r\n";
$headers .= 'Bcc: {$to}' . "\r\n";

if(mail($to, $subject, $message, $headers)){
    echo 'ok';
}

but see what is happend every user see the full list of the users

alt text

+3  A: 

Your call to mail is passing the $to as the to parameter meaning those emails will be be in the to header try passing an empty string instead. You are passing the info into the bcc header so the email should still get to them that way.

Jeff Beck
+1  A: 

That is because you have put all the users in the "to" line. You are also passing them into the "bcc" line too so just doing this may help you but as far as I know you need at least one address in the to line (although this may not be the case). It'll look pretty strange for each person doing it that way though.

The best way to avoid these issues would be to send the email multiple times, once to each user. To modify your code example to do this, I'd do something like the following:

$toAddresses = array("[email protected]", "[email protected]");
$subject  = "Mini-mass Emailer";
$message  = "<a href='#'>Hello World</a>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <[email protected]>' . "\r\n";

foreach ($toAddresses as $to) {
    if(mail($to, $subject, $message, $headers)){
        echo "OK - sent message to {$to}";
    }
}
Splash
but i think will cause in inceasing the server load
moustafa
Yes it will do, but I am assuming it should not be that much of an issue. If you have to send to a very large number of recipients, splitting them up and running a subset each time might be wise. If it is a relatively small amount, the extra load will be nothing worth worrying about.
Splash
the number is 200 email
moustafa
Not too many then. A good way to reduce load on the server is to schedule it for a low-activity point. In addition, rather than firing them all off in the loop you could put in something to introduce a little delay between each one. That'll avoid overwhelming your mail server too quickly.
Splash
A: 

The easiest way is to take this Mail-Class of phpguru.org: http://www.phpguru.org/static/htmlMimeMail5

There you can specify with setBcc() the addresses which should be "blind", it's pretty easy and works well. I use this class in every project.

Best Regards.

Tim