Home Forums Newsletter Plugin Support Sending newsletter from PHP script

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #31413
    mateusz.gr
    Participant

    I need to send newsletter X to user Y using PHP.

    I am able to get email and user, but when I try to feed that to send method, nothing happens. When I enabled wp_debug, there is a bunch of notices about “trying to get property of non-object…”, which is related to $user object

    The code I’m using:

    Newsletter::instance()->send(
    	Newsletter::instance()->get_email(1),
    	Newsletter::instance()->get_user('user@example.com')
    	);

    I also tried to get user like that:

    Newsletter::instance()->get_user_by_wp_user_id($userid) but the result is the same.

    How can I send specified newsletter to specified user from PHP?

    #31415
    mateusz.gr
    Participant

    OK, I havent noticed the second parameter of send() should be an array of users, not a single user. When I changed my code to:

    Newsletter::instance()->send(
    Newsletter::instance()->get_email(1),
    [Newsletter::instance()->get_user(‘user@example.com’)]
    );

    everything works fine. Please close this thread.

    #31536
    Stefano
    Keymaster

    Great! 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.