lzacharyjw
lzacharyjw

Reputation: 1

Adding BCC in PHP's mail function

Ok this is what I have, I need to get this where it will send to email address blind CC of the email. Ideas? I have tried using the $BCC option and it doesn't seem to work for me. And i would rather have it that each didn't know where it was going to.

<?PHP 
$to = "[email protected]; [email protected]";
$subject = "Subject";
$headers = "who it's from";
$forward = 1;
$location = "Thank you Address.html";

$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 



$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n"; 

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    foreach ($_POST as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}
else {
    foreach ($_GET as $key => $value) { 
        $msg .= ucfirst ($key) ." : ". $value . "\n"; 
    }
}

mail($to, $subject, $msg, $headers); 
if ($forward == 1) { 
    header ("Location:$location"); 
} 
else { 
    echo "Thank you for submitting our form. We will get back to you as soon as possible."; 
} 

?>

Ok this is what i've tried, and it still doesn't seem to be working, i know i'm missing something somewhere. i know that when it i can finally if ever get it to send as a bcc i want it to send it with the same subject as the other as well as who it's from.

$to = "[email protected]"; 
$subject = "subject1"; 
$headers  = 'Bcc: [email protected]' . "\r\n"; 
$headers  = 'From: Complaint' . "\r\n"; 
$forward = 1; 
$location = "thank-you.html";

    $date = date ("l, F jS, Y");  
    $time = date ("h:i A");

Upvotes: 0

Views: 180

Answers (2)

Magicianred
Magicianred

Reputation: 566

The problem is you override the value of $headers, use .= the second time. try it:

$to = "[email protected]"; 
$subject = "subject1"; 
$headers  = 'Bcc: [email protected]' . "\r\n"; 
$headers  .= 'From: Complaint' . "\r\n"; 
$forward = 1; 
$location = "thank-you.html";

    $date = date ("l, F jS, Y");  
    $time = date ("h:i A");

Enjoy your code!

Upvotes: 0

Mr. Llama
Mr. Llama

Reputation: 20899

You need to specify the BCC as part of the additional headers to the mail command.
From the documentation example:

$to  = '[email protected], [email protected]';

// subject
$subject = 'MESSAGE SUBJECT';

// message
$message = 'MESSAGE BODY HERE';

// Additional headers
$headers  = 'Bcc: [email protected], [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

Upvotes: 1

Related Questions