Forum Moderators: mack

Message Too Old, No Replies

Sending email with CC and BCC

Sending email with CC and BCC

         

itnecor

6:19 am on Oct 13, 2005 (gmt 0)

10+ Year Member



How can I send a message with BCC and CC? I tried the codes below but it doesn't work although it register in the header information but it did send the message in the address I have put in the CC and BCC.

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: sample.domainname.com\r\n";
$headers .= "CC: sample2.domainname.com\r\n";
$headers .= "BCC: sample3.domainname.com\r\n";
$mail_body = "Sample MEssage";
$Subject = "Sample Subject";
mail($email_to, $Subject, $mail_body, $headers);

Please help!

Many Thanks!

darthgus

2:25 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



I assume that this is for a mailto link?

mailto:username@mydomain.com?cc=someone@somewhereelse.com

so just add "?cc=address" and / or "?bcc=address" and / or "?subject=subjectline" and / or "?body=bodyofemail"

Please note that anyone will be able to spot the CC or BCC from the code. and spiders can still steal them.

Might want to look at javascript to replace the mailto links.

itnecor

2:38 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



I forgot to tell you that the above script is written in PHP, that is why I'm expecting a PHP answer.
Thanks!

JKMitchell

4:04 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



Did you mean
$headers .= "BCC: sample3.domainname.com\r\n";

or sample3@domainname.com?

jatar_k

4:20 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think JKMitchell hit it but just an added note on setting up mail headers in PHP

sometimes the order can make all the difference, I personally would set yours like so

$headers = "From: sample.domainname.com\r\n";
$headers .= "CC: sample2.domainname.com\r\n";
$headers .= "BCC: sample3.domainname.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

I have spent tons of time with mail headers, sometimes you may need to swap the last 2 as well.

itnecor

4:22 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



CORRECTION with my question above:

How can I send a message with BCC and CC? I tried the codes below but it doesn't work although it register in the header information but it did NOT send the message in the address I have put in the CC and BCC.

----------------------------------------------
<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: sample.domainname.com\r\n";
$headers .= "CC: sample2.domainname.com\r\n";
$headers .= "BCC: sample3.domainname.com\r\n";
$mail_body = "Sample MEssage";
$Subject = "Sample Subject";
mail($email_to, $Subject, $mail_body, $headers);
?>

-------------------------------------------------
Please help!

Many Thanks!

jatar_k

4:24 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ack

I meant to make the corrections that JKMitchell mentioned, sorry, your capitalization may be an issue as well

$headers = "From: sample@domainname.com\r\n";
$headers .= "Cc: sample2@domainname.com\r\n";
$headers .= "Bcc: sample3@domainname.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";