PHP Developers Network
http://forums.devnetwork.net/

how to use new Swift_RecipientList(); in v4
http://forums.devnetwork.net/viewtopic.php?f=52&t=97243
Page 1 of 1

Author:  ashleyK [ Thu Mar 19, 2009 9:24 am ]
Post subject:  how to use new Swift_RecipientList(); in v4

Hi, i'm just trying out v4 for the first time and I can't find anything about new Swift_RecipientList(); in the manual. Does it still exist, or has it been replaced?

I used to use the following (where $email was an array with my recipients in)

$recipients = new Swift_RecipientList();
foreach($email as $emailkey => $emailval) {
$recipients->addTo($emailval);
}
$swift->batchSend($message, $recipients, new Swift_Address("mailorder@xxx.com", "xxx"));

what is the new equivalent please?

Author:  Chris Corbyn [ Thu Mar 19, 2009 8:32 pm ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

It doesn't exist anymore... it's no longer needed.

You just add the recipients to the $message object manually via setTo() etc. There's a new addTo() method that isn't yet documented.

Lot's has change in version 4 so you basically need to just read the documentation for usage information.

Author:  Chris Corbyn [ Fri Mar 20, 2009 3:28 am ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

While I say it doesn't exist anymore, the facility is still there if you prefer to use it. The naming is different though.

It works like this:

Syntax: [ Download ] [ Hide ]
$recipients = new Swift_Mailer_ArrayRecipientIterator(array(
  'person-one@domain.com' => 'Name 1',
  'person-two@domain.com' => 'Name 2'
));
 
$mailer->batchSend($message, $failures, $recipients);


The second parameter $failures is not related; it's just where Swift Mailer v4 dumps the list of failed recipients.

ArrayRecipientIterator used in the code above is a simple implementation of Swift_Mailer_RecipientIterator which simply defines two methods: hasNext() and nextRecipient(). This means you can provide your own implementation that looks up recipients from a database on-the-fly.

See the file: lib/classes/Swift/Mailer/RecipientIterator.php for more details on how to implement that if you need it.

Author:  ashleyK [ Fri Mar 20, 2009 8:02 am ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

Hi Chris, i'm not sure I understand, I just need to know the easiest way if I already have an array simply containing a bunch of e-mail addresses, how to pass this information to the mailer.

Is it possible to simply use

$mailer->batchSend($message, $failures, $recipients);

If $recipients is a simple array containing just e-mail addresses, or do they need to be formatted in some way?

Thanks
Ashley

Author:  ashleyK [ Fri Mar 20, 2009 8:20 am ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

Actually after a bit of tinkering about i've figured it out for myself, sorry for being a dummy!

Keep up the amazing work Chris! :D

Author:  ashleyK [ Mon Mar 30, 2009 9:21 am ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

Hi, I can only get the Swift_Mailer_ArrayRecipientIterator to send to the first address in my array.

If I use the following to populate my array, while looping through the database (I don't need a 'name' value)

$emails['$current email address from database'] = '';


I get for instance, with print_r($emails):

Array
(
[test1@test.com] =>
[test2@test.com] =>
[test3@test.com] =>
)


Then if I use

$recipients = new Swift_Mailer_ArrayRecipientIterator($emails);
$mailer->batchSend($message, $failures, $recipients);

it only sends to the first e-mail address in the list

Please can you let me know what I am doing wrong?

Thanks
Ashley

Author:  ashleyK [ Mon Mar 30, 2009 9:36 am ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

Following on, even when I use this code exactly and substitute the two e-mail addresses for addresses I can test with, I only get the first one sent

Syntax: [ Download ] [ Hide ]
$recipients = new Swift_Mailer_ArrayRecipientIterator(array(
  'person-one@domain.com' => 'Name 1',
  'person-two@domain.com' => 'Name 2'
));
 
$mailer->batchSend($message, $failures, $recipients);


**edit - this seems to be a problem with gmail which will only show one e-mail at a time if two addresses are forwarded to it at exactly the same time,**

Author:  ashleyK [ Mon Mar 30, 2009 10:17 am ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

If I use the sample code from http://swiftmailer.org/docs/batchsend-method

I can get it to work if I 'hard code' the email addresses in there.

I need to know the exact syntax to use to populate an array which I can use with the iterator, as it just doesn't seem to be working the way I am using it.

Author:  mrdebian [ Mon Mar 07, 2011 4:08 pm ]
Post subject:  Re: how to use new Swift_RecipientList(); in v4

This is a very old thread but got the same problem and didn't find anything related on Internet.
ashleyK, did you manage to make it work?

Unfortunately there is any relative doc under Swiftmailer's web site.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/