PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Oct 23, 2019 11:44 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Thu Mar 19, 2009 9:24 am 
Offline
Forum Newbie

Joined: Tue Mar 18, 2008 8:10 am
Posts: 11
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?


Top
 Profile  
 
PostPosted: Thu Mar 19, 2009 8:32 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
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.


Top
 Profile  
 
PostPosted: Fri Mar 20, 2009 3:28 am 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
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.


Top
 Profile  
 
PostPosted: Fri Mar 20, 2009 8:02 am 
Offline
Forum Newbie

Joined: Tue Mar 18, 2008 8:10 am
Posts: 11
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


Top
 Profile  
 
PostPosted: Fri Mar 20, 2009 8:20 am 
Offline
Forum Newbie

Joined: Tue Mar 18, 2008 8:10 am
Posts: 11
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


Top
 Profile  
 
PostPosted: Mon Mar 30, 2009 9:21 am 
Offline
Forum Newbie

Joined: Tue Mar 18, 2008 8:10 am
Posts: 11
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


Top
 Profile  
 
PostPosted: Mon Mar 30, 2009 9:36 am 
Offline
Forum Newbie

Joined: Tue Mar 18, 2008 8:10 am
Posts: 11
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,**


Last edited by ashleyK on Tue Mar 31, 2009 6:18 am, edited 2 times in total.

Top
 Profile  
 
PostPosted: Mon Mar 30, 2009 10:17 am 
Offline
Forum Newbie

Joined: Tue Mar 18, 2008 8:10 am
Posts: 11
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.


Top
 Profile  
 
PostPosted: Mon Mar 07, 2011 4:08 pm 
Offline
Forum Newbie

Joined: Thu May 10, 2007 4:38 am
Posts: 9
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group