Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 发布发布状态时发送电子邮件wordpress_Php_Wordpress - Fatal编程技术网

Php 发布发布状态时发送电子邮件wordpress

Php 发布发布状态时发送电子邮件wordpress,php,wordpress,Php,Wordpress,我有一个自定义的职位,这是提交的访客从前端。访问者提交的帖子状态为挂起 现在,当管理员将文章状态从“挂起”更改为“发布”时,我想向这篇文章的作者发送一封电子邮件。按自定义字段收集的作者电子邮件 function send_mails_on_publish( $new_status, $old_status, $post ) { if ( 'publish' !== $new_status or 'publish' === $old_status or 'trainee' !== get_

我有一个自定义的职位,这是提交的访客从前端。访问者提交的帖子状态为挂起

现在,当管理员将文章状态从“挂起”更改为“发布”时,我想向这篇文章的作者发送一封电子邮件。按自定义字段收集的作者电子邮件

function send_mails_on_publish( $new_status, $old_status, $post ) {
    if ( 'publish' !== $new_status or 'publish' === $old_status or 'trainee' !== get_post_type( $post ) )
        return;

    $author = get_post_meta( $post_id, $tr_user_reg_email, true );

    $body = sprintf( 'Hey there is a new entry!
        See <%s>',
        get_permalink( $post )
    );


    wp_mail( $author, 'New entry!', $body );
}
add_action( 'transition_post_status', 'send_mails_on_publish', 10, 3 );

这就是我正在尝试的。但这是行不通的。有人能帮我吗?提前感谢:

您的主机提供商有任何电子邮件限制吗?特别是如果它是免费的主机。如果是这样的话,这可能就是它不起作用的原因。如果不是,可能只是一个小的打字错误。在我看来,你也错过了你的if语句的{}。

叶从


为什么您具有或“发布”==$old\u状态你不是只检查某个东西是否发布了吗?如果发布中删除了某个内容,则不会。如果发布是一个测试站点,则可以尝试查看您是否通过了发布,如果尝试var_dump$author;-它不应该是$post->ID而不是$post\u ID吗?这是一个收集的片段,或者“发布”==$old\u状态?不需要。只需要检查新发布的postalso,在添加操作之前,您没有关闭函数。函数已关闭,请查看代码块的底部,可能我无法完美地包装代码块
function on_publish_pending_post( $post ) {
// A function to perform actions when a post is published.

if ( "trainee" === get_post_type() ) { // check the custom post type

    $name   = get_the_title( $post->ID );

    // get email from custom field
    $author = get_post_meta( $post->ID, "tr_user_reg_email", true );

    $subject = "mail subject";

    $body    = "mail body";

    $headers = array (
        'From: "your name" <no-reply@your-domain.com>' ,
        'X-Mailer: PHP/' . phpversion(),
        'MIME-Version: 1.0' ,
        'Content-type: text/html; charset=iso-8859-1'
    );
    $headers = implode( "\r\n" , $headers );

    wp_mail( $author, $subject, $body, $headers );
}
}
add_action( "pending_to_publish", "on_publish_pending_post", 10, 1 );