I use the PEAR Mail package quite often in projects that require sending email -- either user-generated or system-level notification emails. I recently wrote something at work that required CCing the user a copy of the email. My first thought was that simply adding CC headers with the users' email address would suffice, but that just isn't the case.
Since mail headers can be modified to state anything you want, PEAR Mail doesn't actually use them to to figure out where to send the email (adding the CC header works fine and the users' email address even shows up in the CC field, but they never receive the email).
A comment by Armin Frey that I found on the PEAR bug page for this problem explains what's going on and offers a solution:
[2007-07-06 15:22 UTC] arminf (Armin Frey)
It seems that the Recipients decides where to send the e-mail and the
headers decide how to display it.
The simple solution is that you add all the addresses to $recipients.
Here is the code I used:
$to = '[email protected]';
$cc = '[email protected]';
$recipients = $to.", ".$cc;
$headers['From'] = '[email protected]';
$headers['To'] = $to;
$headers['Subject'] = 'Test message';
$headers['Cc'] = '[email protected]';
$headers['Reply-To'] = '[email protected]';
$send = $mail->send($recipients, $headers, $body);
The solution works perfectly. Now the email addresses show up in the correct fields and all the recipients receive the email.
Unfortunately, this method does not work for BCCing users. I wonder if BCCing is even possible with PEAR Mail or if I'll need to find something else. To Blind CC (aka, BCC) an address, simply add the address to the
$recipients, but not to any of the
$headers (thanks Jason!).