I use this code below to send email after post send to draft. But after this I need also send emails for subscribers. I have tried to use newsletter plugin to get subscribers via REST API. But is there any solution to get those subscribers and send new email if new post published?

 * Send an email notification to the administrator when a post is published.
 * @param   string  $new_status
 * @param   string  $old_status
 * @param   object  $post
function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) {
    if ( $new_status !== 'draft' || $old_status === 'draft' )
    if ( ! $post_type = get_post_type_object( $post->post_type ) )

    // Recipient, in this case the administrator email
    $emailto = get_option( 'admin_email' );

    // Email subject, "New {post_type_label}"
    $subject = 'New ' . $post_type->labels->singular_name;

    // Email body
    $message = 'View it: ' . get_permalink( $post->ID ) . "\nEdit it: " . get_edit_post_link( $post->ID );

    wp_mail( $emailto, $subject, $message );

add_action( 'transition_post_status', 'wpse_19040_notify_admin_on_publish', 10, 3 );

It does not need to use newsletter API, but then what opportunities I have to get subscribers via REST api and then use this code to send everyone email if new post published.

It should work as:

 1. Page visitors can add email through input field (REST api)
 2. Email added to list
 3. When new post published, each list email will be emailed.

One solution I think can be something like making list of email-s (But is there any good plugin for making just a list where can delete and so on) and then go through this list and send emails.

It should use REST api because I have frontend ReactJS and I use wp as backend.


  • 1
    you can try this for manage newsletters wordpress.org/plugins/mailpoet but this plugin doesn't look like using REST API then you need to create custom routes. – Kaperto Dec 16 '19 at 7:09

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.