Click to See Complete Forum and Search --> : Cc and bcc features for email system


Jellybean
12-20-2004, 06:59 AM
Hi,

I am currently developing something similar to an email system.

I am able to send email by using the to in the header.

I would like to extend my codes to include cc and bcc features in the system as well.

Can anyone advise on the approach?

Any advise is most appreciated.

Thank you for reading!

Regards,
Jellybean
:D

scragar
12-20-2004, 07:04 AM
for CC you just need to send the mail to them as normal, but for BCC you'll have to send them without the To and CC feilds, if possible just put them into the tofeild, that way they think it's just to them.

Jellybean
12-20-2004, 07:15 AM
Hi,

This is my code for the html email:

<?php
function send_email($to_addr,$cc_addr,$subject,$message)
{
//input variables
$from_addr = "jellybean@yahoo.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";



$path_to_sendmail = "/usr/sbin/sendmail";
$fp = popen("$path_to_sendmail -Am -t", "w");

$num = fputs($fp, "From: $from_addr\n");
$num = fputs($fp, "To: $to_addr\n");
$num = fputs($fp, "Cc: $cc_addr\n");
$num += fputs($fp, "Subject: $subject\n");
$num += fputs($fp, "$headers\n\n");
$num += fputs($fp, "$message\n\n");


pclose($fp);

//return infomation
if ($num > 0) {
//return 1;
echo "Your mail has been sent out!";
} else {
//return 0;
echo "Sorry there was a problem to send email!";
}
}
?>


Can you advise? Thanks

Jellybean
:D

shimon
12-20-2004, 07:40 AM
Hmm...is there any reason why you're using sendmail and not the mail() function?

Either way, CC and BCC are nothing more than SMTP headers, so you can build them into your $headers string. Check out Example 4 in the manual:

http://www.php.net/function.mail

Jellybean
12-20-2004, 07:54 AM
Hi,

Thanks for the link.

Is this what you mean?

<?php
function send_email($to_addr,$subject,$message)
{
//input variables
$from_addr = "jellybean@yahoo.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";


$path_to_sendmail = "/usr/sbin/sendmail";
$fp = popen("$path_to_sendmail -Am -t", "w");

$num = fputs($fp, "From: $from_addr\n");
$num = fputs($fp, "To: $to_addr\n");
$num += fputs($fp, "Subject: $subject\n");
$num += fputs($fp, "$headers\n\n");
$num += fputs($fp, "$message\n\n");


pclose($fp);

//return infomation
if ($num > 0) {
//return 1;
echo "Your mail has been sent out!";
} else {
//return 0;
echo "Sorry there was a problem to send email!";
}
}
?>

Can I not include the to in the header, just like my previous code?

Thanks

Jellybean

shimon
12-20-2004, 08:45 AM
Yes, you could do that. In fact, since you're piping your message directly to sendmail (although I'm still not certain why you wouldn't use mail() - that's what it's there for) you could build the whole thing as a single string. How you do that is pretty much up to you - regardless of whether you put the headers in a seperate variable or not.

Jellybean
12-20-2004, 10:43 AM
Hi,

I have tried the above code, but it doesn't work.

I am wondering where has it gone wrong.

Any advise is most appreciated.

Thanks.

Jellybean
:D

Jellybean
12-20-2004, 01:57 PM
Hi,

May I know why does the code works sometimes for cc, but not all the time?

bcc is not working at all in this case.

Any advise is most appreciated.

Thanks!

Regards,
Jellybean
:D

Jellybean
12-21-2004, 11:42 AM
Hi,

the code is finally working.

However, majority of the emails ended up in the bulk mail of the Yahoo! email system.

Is there any particular reason why is this so?

Any methods to combat this problem?

Any advise is most appreciated.

Thanks for reading!

Regards,
Jellybean
:D