0

Im trying to write a script with which I can BCC email a large amount of people, but it's not working.

        $headers = 'From: host@host.com' . "\r\n" .
          'Bcc: user1@mail.com, user2@mail.com, user3@host.com' . "\r\n" .
          'Reply-To: host@mail.com' . "\r\n" .
          'MIME-Version: 1.0' . "\r\n" .
          'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
          'X-Mailer: PHP/' . phpversion();
        mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $headers); 

Whenever I run it, the script mails to only the server's owned email addresses. For example, in the above script, user3@host.com would get the email, but user1 and user2 wouldnt. Even worse, I can only actually reach user 1 or 2 by making them the $to field, but that wouldnt even work if theres still any Bcc specified.

I did not originally create this code, I'm merely trying to modify code created by the previous owner, so if I'm missing anything obvious, I'm sorry!

Thanks in advance!

user3394131
  • 199
  • 13
  • 1
    don't build mime emails yourself. it's painful, and far too easy to screw up. use PHPmailer or Swiftmailer. they both make it utterly trivial. – Marc B Mar 07 '14 at 19:34
  • If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with RFC. – viljun Mar 07 '14 at 20:39
  • It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient. For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages. – viljun Mar 07 '14 at 20:39

0 Answers0