PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Hiding Multiple Recipient Addresses

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail
View previous topic :: View next topic  
Author Message
paracelsus



Joined: 01 Jan 2010
Posts: 3

PostPosted: Fri Jan 01, 2010 5:55 am    Post subject: Hiding Multiple Recipient Addresses Reply with quote

Hi

Happy New Year to all Very Happy

Using Mail with "mail" backend - is it possible, when emailing multiple recipients (which is why I'm using the package) to prevent the email displaying all the recipient addresses rather than just the actual recipient's?

A solution would be much appreciated

Thanks

Mark
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Jan 01, 2010 1:02 pm    Post subject: Reply with quote

You're looking for the BCC header.
Back to top
View user's profile Send private message
paracelsus



Joined: 01 Jan 2010
Posts: 3

PostPosted: Fri Jan 01, 2010 1:36 pm    Post subject: Reply with quote

mark wrote:
You're looking for the BCC header.


I'm not looking to send copies where I would utilise BCC, rather the same email to multiple recipients - as in a mailing list.

Am looking for somthing within Mail to accomplish this rather than have to set up the mail distribution system to send to a dummy address just to get BCC's out.

Thanks

Mark
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Jan 01, 2010 1:44 pm    Post subject: Reply with quote

paracelsus wrote:

I'm not looking to send copies where I would utilise BCC, rather the same email to multiple recipients - as in a mailing list.


Hmm, this sounds as if a loop over all your addresses (calling $mail->send(...) each time) would do the job. Or am I mising something here?
Back to top
View user's profile Send private message
paracelsus



Joined: 01 Jan 2010
Posts: 3

PostPosted: Fri Jan 01, 2010 3:05 pm    Post subject: Reply with quote

mark wrote:
Hmm, this sounds as if a loop over all your addresses (calling $mail->send(...) each time) would do the job. Or am I mising something here?


Not sure - was looping through recipients using standard PHP mail() function but its not recommended for large numbers of emails - apparently it opens and closes an SMTP socket for each email, which is inefficient

PHP manual suggests using PEAR::Mail instead, I assume it opens an SMTP socket, sends to all recipients, then closes the socket. Wouldn't your suggestion result in the open/close/reopen scenario I'm trying to avoid?

I don't know one way or the other, this is the first PEAR package I've used & the documentation doesn't clarify. Hence me posting this forum topic.

Thanks

Mark
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Jan 01, 2010 4:51 pm    Post subject: Reply with quote

The Mail package offers only the send() method to send a single method. If you provide multiple addresses in the send() call, all will be visible to every recipient unless you use the BCC header.

You might want to look into the three different supported mailer backends, maybe one of them is a better solution than using PHP's mail() function.

There is also the Mail_Queue package in PEAR that allows to send bunches of mails via the Mail package.
Back to top
View user's profile Send private message
davis



Joined: 07 Jan 2010
Posts: 5
Location: Toronto

PostPosted: Fri Jan 08, 2010 12:44 am    Post subject: Reply with quote

My tests with PEAR Mail, is that multiple recipients are send individual messages.

E.g.
Code:
$recipients = '[email protected],[email protected],[email protected]';
$headers['From']    = '[email protected]';
$headers['Subject'] = 'Test message via PEAR Mail + SENDMAIL';

$body = 'Recipients not BBCd, but should be hidden from each other because PEAR sends 1 at a time. ';

$params['sendmail_path'] = '/usr/sbin/sendmail';

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);
$mail_object->send($recipients, $headers, $body);
[/code]
Back to top
View user's profile Send private message
customframer



Joined: 23 Jan 2010
Posts: 1
Location: Indianapolis, IN

PostPosted: Sat Jan 23, 2010 5:44 am    Post subject: Reply with quote

Don't loop through addresses and send them one at a time.

You can create an array of addresses to send to and then use a single address in the array that will show as the recipient on all messages.

There are two ways to create a list of multiple recipients.

One is to create an array like

Code:

$RECIPIENTS = array();
$RECIPIENTS[] = "John Doe <[email protected]>";
$RECIPIENTS[] = "Mike Smith <[email protected]>";
$RECIPIENTS[] = "Karen Jones <[email protected]>";


The second is to create a comma deliminated list in a variable like
Code:

$strRecipients = "John Doe <[email protected]>,John Doe <[email protected]>,Karen Jones <[email protected]>";


The key to what shows in the to field when people receive the message is what is in the To parameter of the headers array.

If you use the comma delimited string variable then all of the addresses will show in the message header.

If you use the array you will find Array in the to field. That keeps everyone else from seeing the other addresses but is malformed and could cause rejection by spam filters.

If you want to hide the addresses from other people, make the To parameter the address of the sender.

So, to show all addresses in the To field of a message to multiple recipients your code would look something like this




This array can now be used in both places and will show all of the recipients in the To field in your message.

I use this method when I am sending to a small list of recipients that I want to allow to use the Reply-to-All option for replying.

So your code would look like this (note I'm using authenticated smtp)

Code:
include('Mail.php');

// Create the comma delimited string of recipients
$strRecipients = "John Doe <[email protected]>,John Doe <[email protected]>,Karen Jones <[email protected]>";

$message = "Some message text";

$from = "Eric Smith <[email protected]>";
$to = $RECIPIENTS;
$subject = "Your message subject;

$host = "localhost";
$username = "[email protected]";
$password = "somepassword";

$headers = array (
   'From' => $from,
   'To' => $strRecipients,
   'Subject' => $subject,
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);


That code will send a message to all of the recipients in the comma delimited string and the address of each recipient will be shown in the To field. I use this method when I need for people to use the Reply-to-all feature in their e-mail clients.

Now, to hide them you need to make one small change to the code above. This time I'm using an array because I will not be using that in the headers.

In the headers array, instead of using the array $RECIPIENTS for the To field, change it to something like "Undisclosed Recipients <$fromEmail>"

So your code would look like this

Code:
include('Mail.php');

// Create the array of recipients
$RECIPIENTS = array();
$RECIPIENTS[] = "John Doe <[email protected]>";
$RECIPIENTS[] = "Mike Smith <[email protected]>";
$RECIPIENTS[] = "Karen Jones <[email protected]>";

$message = "Some message text";

$from = "Eric Smith <[email protected]>";
$to = $RECIPIENTS;
$subject = "Your message subject;

$host = "localhost";
$username = "[email protected]";
$password = "somepassword";

$headers = array (
   'From' => $from,
   'To' => "Undisclosed Recipients <[email protected]>",
   'Subject' => $subject,
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);


Now all of the recipients will get an e-mail with "Undisclosed Recipients <[email protected]>" in the To field instead of all of the recipients addresses.

Using the array, or comma delimited list for the recipient variable is more efficient than looping through a list or array and calling the send() function for each address to hide recipients. The only time I do that is when I need to add recipient specific information to the message body.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement