FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=8047&edit=1

ID: 8047
Comment by: eis_ltd
Reported By: mail at evinsol dot co dot uk
Summary: Cc and Bcc handling
Status: Bogus
Type: Bug
Package: Mail
Operating System: FC5
Package Version: 1.1.10
PHP Version: 5.1.4
New Comment:

Have you tried using $message->addTo, $message->addCc, etc.? These made
the difference for me.


Previous Comments:
------------------------------------------------------------------------

[2011-04-19 16:48:11] cami

This IS (or at least most of it is) a bug in PEAR Mail_mail.

PHP mail() manual explicitly states that CC/BCC recipients should be
specified in extra headers ONLY, not in the recipients argument.

in contrast Mail::send() manual explicitly states that ALL envelope
recipients (including CC/BCC) must be listed in the recipients
parameter.

Thus, Mail_mail MUST filter out all envelope recipients that are listed
in a CC/BCC header before calling mail(). This is a mail() limitation
that can only be worked around by inspecting message headers.

HOWEVER the fact that some mail() backends or php patches (like suhosin)
ignore the CC/BCC headers passed to mail() is obviously an error in
mail() and not in PEAR Mail_mail.

Please fix the first part as switching the mailer backend must not
change mail::send() semantics! Currently, one must manually detect the
backend and filter CC/BCC from recipients if (and only if) it is
Mail_mail.

------------------------------------------------------------------------

[2010-11-25 13:07:18] mcnaldo

Thank you Brozra, that was a great tip! Specifically the part about the
PEAR module understanding if you put the To, Cc and Bcc addresses into
an array:

/* Combine the TO and BCC here - PEAR SMTP must have all e-mails as the
main recipient. The KEY => VALUE assignments here are understood by the
PEAR module and will route them appropriately. */ $smtp_to = array (
'To' => $to, 'Bcc' => $bcc_emails);


Just to make it clear. The header part only affects how the message
looks, not where it gets sent. The send part specifies where to send the
messages (and also affects what shows up in the 'To' part of the
message).

------------------------------------------------------------------------

[2010-11-10 07:10:20] brozra

Switch to a hosting company that has the latest PEAR modules. That
would probably be the easiest solution. No point in beating yourself up
on trying to find a solution for outdated software.

Shameless company plug follows:
We've got all the latest PEAR, Ruby on Rails, PHP, cPanel, you name it.
We update as soon as a stable release is available for everything.

http://www.brozra.com

------------------------------------------------------------------------

[2010-09-30 22:39:06] slant53

I tried brozra's solution but the bcc addresses are showing up in the To
field of all recipients. I'm at PHP 4.4.9 and Pear Mail 1.1.4 but I
can't upgrade (my host company controls this). Has anyone tried this on
an earlier php or have a different solution.

------------------------------------------------------------------------

[2010-03-24 08:04:20] brozra

Simeruk's solution only works for ONE BCC email address. It won't work
for multiples. Here's a solution that I came up with. It seems to work
just fine with PHP 5.3. It may not be pretty or the shortest code, but
dangit, it works! The same principles can also be applied for CC.
ENJOY!

<?php

/* One odd thing I noticed is that sometimes you have to copy the "Net"
folder from the
"Php" folder to the directory where you are using your script. I don't
know if that's the
case for everyone, but I have had to do it on all my sites on my hosting
server.

Can't get it working? Send me an e-mail: russ.alexander@brozra.com

This solutions is provided AS-IS. If you make modifications, then you
are on your own!
*/

include('Mail.php'); // Must have SMTP PEAR modules installed on your
server

$message = 'Message';
$subject = 'Subject';

/* Recommend that you use an e-mail address from the SAME domain as your
host or it will be marked as SPAM / JUNK. */
$from = "from_email@domain.com"; // Specify the return address here -
yes, you can use a 'noreply' address if you want.
$to = "to_email@domain.com"; // Specify the main recipient here - yes,
you can use a 'noreply' address if you want.

/* For some reason, this was the ONLY way I could get PEAR SMTP to send
BCC emails to all the email addresses with one variable
If you are pulling from a database, then use the following code or
similar:

$sql = "SELECT `email_address` FROM `table` WHERE value='whatever'";
$result = mysql_query($sql);
while ($line = mysql_fetch_array($result,MYSQL_ASSOC)) {
extract($line);
$count=0;
if ($count > 0) { $emails .= ', '; }
$bcc_emails .= $line['email_address'];
$count++;
}
*/
$bcc_emails = "email_one@domain.com, "; // Use the trailing comma and
space after the email address!
$bcc_emails .= "email_two@domain.com, "; // Use the trailing comma and
space after the email address!
$bcc_emails .= "email_three@domain.com"; // No trailing comma. It is
kind of like an array, but not

/* Combine the TO and BCC here - PEAR SMTP must have all e-mails as the
main recipient. The KEY => VALUE assignments
here are understood by the PEAR module and will route them
appropriately. */
$smtp_to = array (
'To' => $to,
'Bcc' => $bcc_emails);

/* Set server information & SMTP function for PEAR SMTP */
$host = "your_mail_host";

/* Best way to avoid using your own personal e-mail here is to setup
another e-mail specifically for this purpose
like smtp_verify@domain.com -- don't forget to discard all incoming
e-mails for that account too! */
$username = "username (or) email for SMTP verification";
$password = "password";

/* The following is not necessary unless you want to send HTML formatted
*/
$content_type = "text/html; charset=iso-8859-1";
$mime_ver = "1.0";

/* Establish the connection for SMTP */
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

/* Generate the headers. No need to include BCC here! If you do, then
the BCC's
aren't blind at all and can be viewed by recipients if they dig deep
enough.
The beauty of it though is that the e-mails will still be sent and the
only
recipient to show will be the TO from the array in $smtp_to!*/
$headers = array(
'From' => $from,
'Return-Path' => $from,
'To' => $to,
'Subject' => $subject,
'Content-type' => $content_type,
'MIME-Version' => $mime_ver);

/* Finally, send the e-mail */
$send_emails = $smtp->send($smtp_to, $headers, $message);
if (PEAR::isError($send_emails)) {
echo $mail->getMessage();
echo "Failed to send message!";
} else { echo "Success. Message sent!"}

?>

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://pear.php.net/bugs/bug.php?id=8047

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJan 16, '12 at 10:46a
activeJan 16, '12 at 10:46a
posts1
users1
websitepear.php.net

1 user in discussion

Eis_ltd: 1 post

People

Translate

site design / logo © 2022 Grokbase