Page 1 of 1
Array syntax...
Posted: Sun Mar 30, 2008 8:27 pm
by Josh1billion
I'm using SwiftMailer and trying to use the
Decorator plugin.
The code shown there goes like this:
Code: Select all
$replacements = array(
"joe@bloggs.com" => array("{name}" => "Joe", "{weather}" => "chilly"),
"fred@perry.com" => array("{name}" => "Fred", "{weather}" => "muggy")
);
I'm trying to do something like that, but I need to split it up into different code pieces (i.e. add an element to the array later in a while loop).
So I'm trying something like this, but it's not working:
Code: Select all
$replacements = array(
"joe@bloggs.com" => array("{name}" => "Joe", "{weather}" => "chilly")
);
// .....................
$replacements[] = "fred@perry.com" => array("{name}" => "Fred", "{weather}" => "muggy");
Of course, the last line is incorrect and throws up a syntax/parse error. What's the correct syntax for that last line?
Re: Array syntax...
Posted: Sun Mar 30, 2008 9:23 pm
by Christopher
Code: Select all
$replacements[] = array("fred@perry.com" => array("{name}" => "Fred", "{weather}" => "muggy");
Re: Array syntax...
Posted: Sun Mar 30, 2008 10:33 pm
by Josh1billion
Did not work.. I think I tried that before at some point in time (when I was trying a bunch of combo's to try to get it to work).
Here's the exact code of what I have now, based upon the code you posted, it "compiles" fine, but Swift Mailer's Decorator plugin (linked to in first post) isn't reading it properly so the array format must be wrong....
Code: Select all
$replacements = array(
"null" => array("[USERNAME]" => "null", "[LEVEL]" => "1", "[CLASS]" => "Warrior")); // just putting in a basic entry to start things off
// ..............
// real data is added here.. the variables are correct
$replacements[] = array($current['username'] => array("[USERNAME]" => $current['username'], "[LEVEL]" => $current['level'], "[CLASS]" => $current['class']));
Re: Array syntax...
Posted: Sun Mar 30, 2008 10:59 pm
by Josh1billion
Ah, probably because I'm using batchSend instead of Send... hold up, trying to fix it...
EDIT: Nevermind, apparently it IS supposed to work with batchSend() too... still don't know what the problem is, then.
Re: Array syntax...
Posted: Sun Mar 30, 2008 11:06 pm
by John Cartwright
batchSend() is only a wrapper of regular send() with some magic error handling fluff, nothing more. It shouldn't have an affect on the decorator plugin.
However, Swift expects the users email to be the key of the array.. so what I don't understand is why you are adding another dimension to the array.
Take a look at
http://swiftmailer.org/wikidocs/v3/plugins/decorator, you should be doing something like
Code: Select all
$replacements[$row['email']] = array("[USERNAME]" => $current['username'], "[LEVEL]" => $current['level'], "[CLASS]" => $current['class']);
Re: Array syntax...
Posted: Sun Mar 30, 2008 11:18 pm
by Josh1billion
Ahh.. the e-mail is the
key of the array, that explains it.

Thanks JCart, it's working now.
(I haven't worked with arrays in PHP much to be honest, I didn't even know that you could have non-numerical keys for arrays

)