"Decorator" functionality in 4.0.0?
Moderators: Chris Corbyn, General Moderators
"Decorator" functionality in 4.0.0?
Am I overlooking something? In 4.0.0 I cannot find a functionality like the Decorator plugin in 3.3.3. I Would like to do some personalisation on batch e-mails. The 3.3.3 documentation says that Decorator saves a lot of execution time because of clever chaching. Doesn't 4.0.0 have something similar?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: "Decorator" functionality in 4.0.0?
Yep, it's the same, except the class has a different name. I just haven't had the time to document it yet (as you can probably see, the documentation is missing a few sections, but I'll get there).
Currently it just takes an Array of replacements. I will probably refactor it to accept a Replacements object provided by the developer.
Currently it just takes an Array of replacements. I will probably refactor it to accept a Replacements object provided by the developer.
Code: Select all
$replacements = array(
'email1@domain.tld' => array('{username}' => 'fred', '{password}' => 'rainbow'),
'email2@domain.tld' => array('{username}' => 'john', '{password}' => 'sunshine')
);
$decorator = new Swift_Plugins_DecoratorPlugin($replacements);
$mailer->registerPlugin($decorator);
$message = new Swift_Message('IMPORTANT: {username}, your password has been reset');
$message->setBody(
"Hello {username},
This is an automated system email regarding your user account. We've reset your password due
to a recent security violation. This is just a matter of precaution.
Your new password is: {password}
Regards,
Admin");
$message->setFrom(array('your@address.tld' => 'The Admin'));
$message->setTo(array(
'email1@domain.tld', 'email2@domain.tld'
));
$mailer->batchSend($message);
/* email1@domain.tld gets this...
Subject: IMPORTANT: fred, your password has been reset
Hello fred,
This is an automated system email regarding your user account. We've reset your password due
to a recent security violation. This is just a matter of precaution.
Your new password is: rainbow
Regards,
Admin
-------------
email2@domain.tld gets this...
Subject: IMPORTANT: john, your password has been reset
Hello john,
This is an automated system email regarding your user account. We've reset your password due
to a recent security violation. This is just a matter of precaution.
Your new password is: sunshine
Regards,
Admin
*/
Re: "Decorator" functionality in 4.0.0?
I haven't been able to get this to work yet... It runs through, doesn't give any errors, but on the $mailer->batchSend($message) part it returns 0 every time.
That's what my code is looking like so far, some calls are to my own functions, but they should be passing back the kind of arrays you've documented above. I took out some things like the SMTP, username and password just so the whole world doesn't see them.
Yeah, it's kind of a mess, I've been re-arranging stuff for a while and re-writing some of my old functions since I moved from version 3 to 4.
******** EDIT ********
Nevermind that... I went back to some of my other code and found out that it wasn't passing the recipient list back correctly. Now it's sending out to people, but it was a blank email. I'll continue to mess around with it and see if I can figure anything out.
**** EDIT ****
Well, got it all working. It really wasn't anything on swift mailers end, it was all my side when I converted things over I either didn't get some POST values correct or just messed something up. I noticed my ->setBody($message) was wrong, $message is what I used to initialize the Swift_Message, but it was also a variable I was passing to my function for the body, so that was a fail.
Code: Select all
require_once 'lib/swift_required.php';
$emails = $this->get_recipients($emails);
$transport = Swift_SmtpTransport::newInstance('smtpserver', 587)
->setUsername('user')
->setPassword('pass');
$mailer = Swift_Mailer::newInstance($transport);
$replacements = $this->build_replacements($email, $id, $template_id);
$decorator = new Swift_Plugins_DecoratorPlugin($replacements);
$mailer->registerPlugin($decorator);
$message = Swift_Message::newInstance($subject, 'text/html')
->setFrom(array('sentfrom' => 'aname'))
->setTo($emails)
->setBody($message);
$numSent = $mailer->batchSend($message);
echo 'Sent: '.$numSent;
Yeah, it's kind of a mess, I've been re-arranging stuff for a while and re-writing some of my old functions since I moved from version 3 to 4.
******** EDIT ********
Nevermind that... I went back to some of my other code and found out that it wasn't passing the recipient list back correctly. Now it's sending out to people, but it was a blank email. I'll continue to mess around with it and see if I can figure anything out.
**** EDIT ****
Well, got it all working. It really wasn't anything on swift mailers end, it was all my side when I converted things over I either didn't get some POST values correct or just messed something up. I noticed my ->setBody($message) was wrong, $message is what I used to initialize the Swift_Message, but it was also a variable I was passing to my function for the body, so that was a fail.