Hi,
I think we're having a problem with the decorator plugin because I'm seeing incorrect information in the replacements which are made. For example, for a given email address we should see the recipient's user id in the message but we are seeing a different user ID.
Psuedo code for the way we use swift is
Create new swift(new Swift_Connection_Sendmail)
Create new SwiftMessage
Attach html and text message parts (including decorator replacement 'tags')
For Each recipient
Create new Swift_RecipientList
Add recipient to RecipientList
Create substitution array for decorator
Attach decorator plugin
swift->send()
End For Each
Disconnect Swift
Anything which is glaringly wrong there?
Many Thanks
James
P.S. We've sent over 2 million legimate opt-in emails in the 2 months since we've been using swift - pretty impressive!
Decorator Plugin Problem
Moderators: Chris Corbyn, General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Decorator Plugin Problem
Don't attach the plugin multiple times inside the loop. That will break it. Build the full array of replacements and attach it before sending all the messages.
Re: Decorator Plugin Problem
HI Chris,
Thanks for the reply. So I should only call swift->send once for all recipients in this batch? Does that mean it will send one message with multiple recipients (in the To: field) or will it still send mutliple individual emails? New pseudo-code below
Create new swift(new Swift_Connection_Sendmail)
Create new SwiftMessage
Attach html and text message parts (including decorator replacement 'tags')
For Each recipient
Create new Swift_RecipientList
Add recipient to RecipientList
Create substitution array for decorator for this recipient
End For Each
Attach decorator plugin
swift->send()
Disconnect Swift
Thanks for the reply. So I should only call swift->send once for all recipients in this batch? Does that mean it will send one message with multiple recipients (in the To: field) or will it still send mutliple individual emails? New pseudo-code below
Create new swift(new Swift_Connection_Sendmail)
Create new SwiftMessage
Attach html and text message parts (including decorator replacement 'tags')
For Each recipient
Create new Swift_RecipientList
Add recipient to RecipientList
Create substitution array for decorator for this recipient
End For Each
Attach decorator plugin
swift->send()
Disconnect Swift
Re: Decorator Plugin Problem
Chris, any response to my reply below?
Thanks
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Decorator Plugin Problem
No, you can still loop with send(), but you should only attach the plugin once (before you start looping). If you don't want to loop and send() at all then use batchSend().
Pseudo:
You could replace that last loop with a batchSend() like this:
Pseudo:
Code: Select all
<?php
$replacements = array();
foreach ($addresses as $address) {
$replacements[$address] = array( /* some replacements */ );
}
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), 'decorator');
foreach ($addresses as $address) {
$swift->send($message, $address, $yourAddress);
}Code: Select all
<?php
$recipients = new Swift_RecipientList();
$replacements = array();
foreach ($addresses as $address) {
$replacements[$address] = array( /* some replacements */ );
$recipients->addTo($address);
}
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), 'decorator');
$swift->batchSend($message, $recipients, $yourAddress);Re: Decorator Plugin Problem
Thanks Chris, will give that a try. Great work as always