Newsletter 2 users

hello,

I modified the newsletter plugin a bit to send the newsletter mail to kirby users.

Is the correct method to filter the users according to their role and to save them in an array ?

/perry

Yes, why not? After all, the original code does the same. You might want to make it more versatile by setting the role through a config option rather then hardcoding it. Or use a Kirby collection.

strange is that the test mail arrives, but not the mail to the user. As I understand the script, an error message should appear if the mails cannot be sent. how can I create a log file with phpMailer?

when i hardcode the array it works however if the array is not created like this:

$to = [];
$users = $kirby->users()->filterBy(‘role’,‘intern’)->toArray();

        foreach ($users as $user):
           array_push($to,$user['email']);
        endforeach;
        return $to;

vs

$to = ['xx@email.com' , 'yy@email.com'];

i don’t understand why. :face_with_monocle:

$kirby is not defined.

can I not use this in a plugin?

No, $kirby is only available in controllers, templates, snippets. Outsite of these files, use kirby() instead of $kirby.

1 Like

Thank you @texnixe