Unable to sent wp_mail on post trash

I am unable to send wp_mail when posts are sent to trash. Below is the function I am using. If anyone could help.

    function post_rejection_email() {

            //Email Setup
            $post_status = get_post_meta( the_ID(), 'post_status', true );
            $post_name = $post->post_title;

            //Email Details
            $email = get_the_author_meta( 'user_email' );
            $author_name = the_author_meta('first_name');
            $subject = 'Sorry, your post has been refused.';
            $post_type = 'event_listing';

            $message = 'Dear ' . $author_name . '. Unfortunately your post: ' . $post_name . ' has been refused.';

            if ($post_status == 'trash' && $post->post_type == $post_type) {        
                    wp_mail($email, $subject, $message); 
    add_action('transition_post_status', 'post_rejection_email', 10, 3);

I am getting no email. Don’t know where I am wrong. Please help.

Read more here: Unable to sent wp_mail on post trash

Leave a Reply

Your email address will not be published. Required fields are marked *