DanielAttard
DanielAttard

Reputation: 3605

PHP Mail function, BCC not working

I am trying to figure out why the bcc part of this PHP mail function is not working in the code below:

function _send_user_email($to, $subject, $message) {
$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: Customer Service <[email protected]>";
$headers[] = "Bcc: <[email protected]>";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, implode("\r\n", $headers));
}

I wouldn't think that there should be any problem specifying a bcc email address that is the same as the From address, but I'm not sure.

When I test this function, the recipient receives the message, but the BCC copy does not come through. Any idea why? Thanks.

Upvotes: 2

Views: 6190

Answers (4)

Houssin Boulla
Houssin Boulla

Reputation: 2859

Try to use Cci like this example:

$headers = array(
    'From' => $from,
    'To' => $to,
    'Cci' => $bcc,
    'Subject' => $subject
);

Upvotes: 0

user2249079
user2249079

Reputation:

try this one in your script you have to change "" to '' and also remove <> then it will be work here i edited your script

function _send_user_email($to, $subject, $message) { 
$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: Customer Service <[email protected]>";
$headers[] = 'Bcc: [email protected]';
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, implode("\r\n", $headers));
}

here my mail function example

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
$headers .= "From: mydemo.com<$your_email>\r\n" .  
$headers .= 'Bcc: [email protected]' . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion(); 
mail($to, $subject, $message, $headers);

Now If You Want To Use Html In Message

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
$headers .= "X-Mailer: PHP/" . phpversion(); 

For Exampe Message
$message .='<table><tr><td></td></tr></table>';

Upvotes: 2

Spudley
Spudley

Reputation: 168685

Seriously, don't use the mail() function -- you're just letting yourself into a world of hurt.

If you want to do anything beyond absolutely the most basic email, I strongly recommend using a decent mail class, such as phpMailer.

It will make things much easier. No more messing around building the headers yourself, or trying to get the mime types working. Sending to multiple addresses, CC and BCC addresses becomes simple, and adding attachments goes from virtually impossible with mail() to dead simple.

Hope that helps.

Upvotes: 2

Taha Ali Adil
Taha Ali Adil

Reputation: 21

it working fine, i have tested the script found that email drop in Junk box.

try to add name of email holder :

"Bcc: Support <[email protected]>";

Upvotes: -1

Related Questions