This topic is locked

Sending mails to Bcc

4/19/2007 3:37:02 AM
PHPRunner General questions
M
mmponline author

I use the following event to send e-mails to users. It works fine (the host must just not have a limit on e-mails to be sent at once)
The only thing I'd like to change in the script, is that the addresses must be put in the Bcc column, as this will ensure better privacy to the receivers. Any suggestions will be appreciated.

global $conn;

$all_emails="";

$mailfrom1 = "From e-mail here";

$strSQL = "select Email from Login where Available='Yes'";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

$all_emails .= $data["Email"].", ";

$all_emails = substr($all_emails,0,strlen($all_emails)-2);

$message="The message here";
$subject="The subject here:";
mail($all_emails [b]//this should be sent via Bcc//[/b], $subject, $message, 'From: '.$mailfrom1);
return true;
J
Jane 4/19/2007

Stephan,
to add BCC field to the email use additional headers in the mail function.

You can find some examples in the PHP documentation:

http://php.net/manual/en/function.mail.php

M
mmponline author 4/19/2007

I've changed the code to the follwing:

$headers= 'Bcc: $all_emails' . "\r"; // as I want these ardresses al added to the Bcc

mail($headers, $subject, $message, 'From: '.$mailfrom1);


I get no error messages, but no mails are sent as well.

D
Dale 4/19/2007

I think you forgot the .= for your header. I think it should be $headers .= 'Bcc ...........
your example

$headers= 'Bcc: $all_emails' . "\r"; // as I want these ardresses al added to the Bcc

M
mmponline author 4/20/2007

This still doesn't work. I get an ndefined variable error.
I found a temporary workaroud, but it's not really what I want, as the From address now contains a "nobody" as sender. At least it's sendng all mails as Bcc.
The code I used:

mail($mailfrom1, $subject, $message, 'Bcc: '.$all_emails); in stead of the
mail($all_emails, $subject, $message, 'From: '.$mailfrom1);



I sat about 3 hours last night to get this sorted. When I use both 'From: '.$mailfrom1 and 'Bcc: '.$all_emails in the same line to get From and Bcc in the correct headers, nothing is sent...