Page 1 of 2

PHP mail and bcc

Posted: Thu Jan 29, 2009 11:58 am
by brianc
I need my php script to send me a bcc cant figure it out.

Mail script now:

$to = $_POST[email];
$subject = "Your login info for Blackford County Classmates";

$message = "Hello $_POST[CurrentName],\nYour login details are:\n\nUsername: $_POST[NewUsername]\nPassword: $_POST[p1]\n\nhttp://www.pcdwifi.com/classmates";

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: PHP/" . phpversion()."\n";

mail($to, $subject, $message, $headers);

Re: PHP mail and bcc

Posted: Thu Jan 29, 2009 12:08 pm
by andyhoneycutt
Add "Bcc: <email address>" to your headers. php mail function

Re: PHP mail and bcc

Posted: Thu Jan 29, 2009 12:10 pm
by brianc
I have tried that and I can't get it to work. I must be missing something.

Re: PHP mail and bcc

Posted: Thu Jan 29, 2009 12:19 pm
by andyhoneycutt
They should be at the end of the header and after you've attached your Bcc address(es), end the line with a carriage return rather than just new line to signify the end of the header, using "\r\n".

-Andy

Re: PHP mail and bcc

Posted: Thu Jan 29, 2009 12:26 pm
by brianc
Can you show me with my mail code above???

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 11:56 am
by andyhoneycutt
try this:

Code: Select all

 
$to = $_POST[email];
$subject = "Your login info for Blackford County Classmates";
 
$message = "Hello $_POST[CurrentName],\nYour login details are:\n\nUsername: $_POST[NewUsername]\nPassword: $_POST[p1]\n\nhttp://www.pcdwifi.com/classmates";
 
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: PHP/" . phpversion()."\n";
 
// Add this line: 
$headers .= "Bcc: email@address.com\r\n";
 
mail($to, $subject, $message, $headers);
 

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 1:05 pm
by brianc
Tried that again. I had already tried same code. No go.
to: email works but I never receive Bcc

Any other ideas?? I really need this to work, I guess it doesn't have to be a Bcc as long as I recieve the email to. I dont care if they know that I'm receiving it too.

Thank you

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 1:12 pm
by brianc
I forgot to tell you, I have tried
1.| $headers .= "Bcc: email@address.com\r\n";

at the beginning, middle and end of headers. And still can't get it to work. I saw where someone said order can make all the differance.

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 1:23 pm
by brianc
I'm sorry, I told you wrong. When I add that line nobody receives a email.

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 1:39 pm
by Bill H
try

Code: Select all

$headers .= 'Bcc: email@address.com' . "\r\n";

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 1:53 pm
by brianc
Tried that and same thing no one gets emails.

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 2:15 pm
by Bill H
Try taking all the other headers out and see if it sends the bcc. If it does then add them back in one at a time, trying again each time. One of the other headers may be interfering with the bcc.

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 2:17 pm
by brianc
Bill,

Ok, I will try that.

Thank you

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 2:24 pm
by Bill H
Actually, I've never used bcc in the mail function, but I'm not althgether sure it's even supposed to send an email, or whether it merely inserts that indication in the email header. You can get the email sent to you by using multiple "to" addresses. If you're going to do that I would not bother with the bcc header, or I would make it a "cc" header, since the multiple "to" addresses will be visible to the recipient.

Code: Select all

$to = $_POST[email] . ", email.address.com";

Re: PHP mail and bcc

Posted: Fri Jan 30, 2009 2:26 pm
by brianc
Took all headers out exept the Bcc. And it still doesn't work. This is strange!