Is there a way to use list data inside an email


I was wondering if there is a way to use List data inside the email ?

I have users and plenty of lists that users are on (or not).
Many users are on some, not all lists etc.

I understand I can create emails for every type list and play with the include and exclude lists tab to make sure each list gets an appropriate email.

But I’m about to send an email that applies to almost everybody, just one parameter in a URL could help deliver better targeted content, and that parameter is depending on the list(s) they’re on.

Any idea ?

Can I call listsSubscriber() in a plugin ?
It doesn’t appear to work

 public function parseOutgoingHTMLMessage($messageid, $content, $destination, $userdata = null)
    $lists = listsSubscriber($userdata[id]) ;

    // Do something with $lists

    return $content;

The only place that I can see that function is in the REST API plugin. In which case it is not that simple to invoke it.

You need to include the appropriate file from that plugin.
The method is static and the class is in a namespace, so it needs to be called as \phpListRestapi\Lists:listsSubscriber() or something like that
Even then, I guess that the plugin was not developed with this in mind.

You might be better off just copying the sql query and including that directly.

Thanks Duncan,

Care to copy a small code snippet that can be used in the plugin function ?
I’m not sure how to do that

@ibPeter This will get the details of the list to which the campaign is being sent and the subscriber belongs. If they belong to more than one list then only one is returned, remove the LIMIT line to return all lists

        global $tables;

        $format = <<<END
FROM %s l
JOIN %s lu ON lu.listid = AND lu.userid = %d
JOIN %s lm ON lm.listid = AND lm.messageid = %d
        $sql = sprintf($format, $tables['list'], $tables['listuser'], $userdata['id'], $tables['listmessage'], $messageid);
        $result = Sql_Query($sql);
        $row = Sql_Fetch_Assoc($result);
        // do something with $row['id'], $row['name] etc

Oh wow, not trivial, I never would have figured that out myself. Thank you.
Will test in a little while.