Jump to content


Photo

Mail Bcc/Cc function not working as expected


  • Please log in to reply
2 replies to this topic

#1 DJMurtz

DJMurtz
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 20 April 2006 - 08:55 PM

I've been trying to get the mail function working with the Cc and Bcc headers. Basicly what I want is an admin to be able to send out an email to all users in the database. However, I do not want all those email addresses to be shown in the To list like this:

email1@test.com, email2@test.com, email3@test.com, etc

I wanted only to show the email of the user in the To list. Now I can accomlish this by doing a while loop with a new email address in each mail send. However, I was under the impression that the Bcc header exsisted to solve this problem.

I figured, that if I put the first email address it gets from the database in the standard place of the mail() funcion, and put the rest of the email addresses in the Bcc header it would all work out, like this:

        while($aSendToAddresses = mysql_fetch_array($qSendToAddresses)) {
            $sSendToAddresses .= ', ' . $aSendToAddresses['email'];
        }
        $sSendToAddresses = substr($sSendToAddresses, 2);
        $sSendToFirstAddress = explode(', ', $sSendToAddresses);
        $sSendToAddresses = str_replace($sSendToFirstAddress[0], '', $sSendToAddresses );
        $sSendToAddresses = substr($sSendToAddresses, 2);
        $sSendToAddresses = 'Bcc: ' . $sSendToAddresses . "\r\n";
        
        mail($sSendToFirstAddress[0], $_POST['mailtitle'], $_POST['mailmessage'], $sSendToAddresses);

However, the result of this script was that indeed all the emails where send, and indeed not all the users where listed in the 'to' list. But the problem was that each email address had the email of the first receipe (defined in $sSendToFirstAddress) in the 'To:' line...

Can anyone help me out to fix this? or is the only solution a while loop of the mail function

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 April 2006 - 10:49 PM

The simple solution is to set the 'to' address to your own address and put ALL recipients in the BCC group.
Legend has it that reading the manual never killed anyone.
My site

#3 DJMurtz

DJMurtz
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 21 April 2006 - 09:03 AM

[!--quoteo(post=367029:date=Apr 21 2006, 12:49 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Apr 21 2006, 12:49 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The simple solution is to set the 'to' address to your own address and put ALL recipients in the BCC group.
[/quote]

That would still mean that all users see my email in the To address but I want it to show only their own address?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users