Search code examples
phpemailsmtpbcc

PHP SMTP BCC, not going through


Recipients named in the BCC/CC (in the headers) are not received. I've found a couple of posts with similar questions, no answers...

The code is below, the question is: "Have any of you had similar problems?"

require_once "Mail.php";

$host = "mail.mailserver.com";
$username = "[email protected]";
$password = "getyourownpassword";

$headers = array ('From' => "User Name <$username>",
                  'To' => $to_,
                  'Cc' => 'Patty <[email protected]>',
                  'Subject' => $subj_,
                  'Content-type' => 'text/html');

$smtp = Mail::factory('smtp',
                      array ('host' => $host,
                             'auth' => true,
                             'username' => $username,
                             'password' => $password));

$mail = $smtp->send($to_, $headers, $mail_msg);

Solution

  • It looks like you're using the PEAR mail module. if you read here You'll see a discussion about the headers passed to the pear module only specifies how the message looks, not to who actually gets it. If you add a CC header, that person will show up as being CC'd but to actually receive it he needs to be added to the recipients array. For BCC, you add them to recpients array, but don't show them in the header.