无法在帖子垃圾箱上发送wp_mail

时间:2017-04-19 07:49:04

标签: php wordpress email

当帖子发送到垃圾箱时,我无法发送wp_mail。以下是我正在使用的功能。如果有人可以提供帮助。

    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);

我没有收到任何电子邮件。不知道我错在哪里。请帮忙。

1 个答案:

答案 0 :(得分:0)

我与Wordpress合作了一点。看起来电子邮件是发送给发送到垃圾箱的帖子的作者,而不是您(除非您将此作为已删除帖子的作者进行测试并且它不起作用)。

如果您还希望除了帖子的作者之外还要通知此事,请尝试在该帖子的下方添加新的邮件功能......

wp_mail($email, $subject, $message); 
wp_mail('youremail@example.com', $subject, $message);

如果它根本不工作,那么Wordpress安装的电子邮件功能就会出现问题。有关wp_mail功能如何工作的更多信息和示例(包括如何配置SMTP邮件等)可以在此处找到: https://developer.wordpress.org/reference/functions/wp_mail/

相关问题