PHP mail and bcc

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

PHP mail and bcc

Post 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);
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: PHP mail and bcc

Post by andyhoneycutt »

Add "Bcc: <email address>" to your headers. php mail function
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post by brianc »

I have tried that and I can't get it to work. I must be missing something.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: PHP mail and bcc

Post 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
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post by brianc »

Can you show me with my mail code above???
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: PHP mail and bcc

Post 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);
 
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post 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
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post 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.
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post by brianc »

I'm sorry, I told you wrong. When I add that line nobody receives a email.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: PHP mail and bcc

Post by Bill H »

try

Code: Select all

$headers .= 'Bcc: email@address.com' . "\r\n";
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post by brianc »

Tried that and same thing no one gets emails.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: PHP mail and bcc

Post 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.
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post by brianc »

Bill,

Ok, I will try that.

Thank you
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: PHP mail and bcc

Post 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";
Last edited by Bill H on Fri Jan 30, 2009 2:27 pm, edited 1 time in total.
brianc
Forum Newbie
Posts: 10
Joined: Thu Jan 29, 2009 11:55 am

Re: PHP mail and bcc

Post by brianc »

Took all headers out exept the Bcc. And it still doesn't work. This is strange!
Post Reply