PHP mail with bcc issue

Discussion in 'PHP' started by ermac2014, Jul 29, 2009.

  1. #1
    hi all,
    i have this php mail code to send emails:

    $body = "test message";
    $title = "test email";
    $from = "notification@aa.com";
    
    $addresses = array('test@hotmail.com', 'test1@gmail.com', 'test3@gmail.com', 'test2@yahoo.co.uk', 'test4@gmail.com', 'test5@gmail.com');
    $emails = implode(',', $addresses);
    $to = "me@hotmail.com";
    
    
        $headers = "From: $from\r\n"; 
    	$headers .= "Bcc: $emails\r\n";
    
    // Now we specify our MIME version
        $headers .= "MIME-Version: 1.0\r\n"; 
    
    // Create a boundary so we know where to look for
    // the start of the data
        $boundary = uniqid("HTMLEMAIL"); 
    
    // First we be nice and send a non-html version of our email
        $headers .= "Content-Type: multipart/alternative;".
                    "boundary = $boundary\r\n\r\n"; 
        $headers .= "This is a MIME encoded message.\r\n\r\n"; 
        $headers .= "--$boundary\r\n".
                    "Content-Type: text/plain; charset=ISO-8859-1\r\n".
                    "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $headers .= chunk_split(base64_encode(strip_tags($body))); 
    
    // Now we attach the HTML version
        $headers .= "--$boundary\r\n".
                    "Content-Type: text/html; charset=ISO-8859-1\r\n".
                    "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $headers .= chunk_split(base64_encode($body)); 
    
    // And then send the email ....
    mail($to,$title,"",$headers);
    PHP:
    the problem is that the function doesnt read the Bcc emails when I try to send the email to other recipients..
    I tried to send through Cc and it worked perfectly.
    does anybody knows whats the problem?
     
    ermac2014, Jul 29, 2009 IP
  2. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #2
    I couldn't tell you offhand what the problem is, but why even bother with BCC? I would just take the BCC email address(es) and make another mail() out of it/them with the same headers, body, and subject.

    Is this an option?
     
    tguillea, Jul 30, 2009 IP
  3. ermac2014

    ermac2014 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    well the problem is that I have 40000 members in my site. and i want to send newsletter to them.
    if I use mail function with each member email it will send new request to the server and imagine i have 40000..
    the host provider will notice this and will tell me that im spamming and will suspend my site for this reason.
    so if i use bcc i can send at least 40 emails at once. it will be somthing like 1000 requests.
    the number of sending mail function request will be lower than before and host provider will not notice that im sending lots of mail requests..thats y i need to use Bcc header..
    any ideas how to make this work?
     
    ermac2014, Jul 30, 2009 IP
  4. ermac2014

    ermac2014 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i just figured it out...
    the host company has disabled this feature in php mail function..
    coz i tried the script on other free webhosting site and it worked fine..
     
    ermac2014, Jul 30, 2009 IP
  5. eyesdrinker

    eyesdrinker Greenhorn

    Messages:
    99
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    20
    #5
    Thank you ermac2014 for sharing the solution, i will check with my web host too. :)
     
    eyesdrinker, Jun 6, 2011 IP