0

We would like to send bulk mail to the user list using wp_mail() function.

Is it possible to send e-mail to users at a certain time (similar to newsletter plugins)? For example, dividing the list of 100 users into 10 groups of 10 people each. Is it possible to send mail to 10 groups with 5 minute intervals?

To give an example instead of theoretical:

We would like to automatically email users who have added "Technology" category to their favorites whenever they post a new post in this category.

How can we edit a function like this to do this?

add_action( 'transition_post_status', 'new_post_notice', 10, 3 );
function new_post_notice( $ID, $post ) {

    if ( 'publish' === $new_status && 'publish' !== $old_status ) {

        $to = //All users who have added "technology" categories to their favorites
        $subject = 'A new post has been published!';
        $message = 'E-mail body.';

        wp_mail( $to, $subject, $message, $headers );

    }
}

Can the sleep() function be used to do this?

  • What do you mean with "adding technology to their favorites"? There are no favorites in WordPress "like saved web pages" in Firefox or Chrome. Practically, you just have to get all e-mails before the "$to //....." like: $blogusers = get_users( array( 'fields' => array( 'email' ) ) ); foreach ( $blogusers as $user ) { $html .= esc_html( $user->email) . '</li>'; } – user3135691 Dec 25 '19 at 13:36
  • @user3135691 Thanks to the system I created, people can add any category to their favorites. And I can list all users who have added the same category to their favorites. No problems here. You may not have fully understood my question. "Is it possible to send e-mail to users at a certain time (similar to newsletter plugins)? For example, dividing the list of 100 users into 10 groups of 10 people each. Is it possible to send mail to 10 groups with 5 minute intervals?" – Faruk Dec 26 '19 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.