BCC email to subscribers

时间:2015-04-11 作者:Auk

我有一个自定义的帖子类型“月报”,需要在发布新公告时向订阅者发送一封盲邮件。

下面的代码可以发送给订阅者,但所有人都可以看到电子邮件。

如何将代码修改为密件抄送订户?

add_action( \'transition_post_status\', \'send_mails_on_publish\', 10, 3 );

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

$subscribers = get_users( array ( \'role\' => \'subscriber\' ) );
$emails      = array ();

foreach ( $subscribers as $subscriber )
    $emails[] = $subscriber->user_email;

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


wp_mail( $emails, \'New entry!\', $body );

}
谢谢大家!

1 个回复
最合适的回答,由SO网友:websupporter 整理而成

第四个参数为wp_mail() 您可以扩展电子邮件的标题。所以you can use BCC there. 这应该可以:

<?php
    $bcc = \'Bcc: \';
    $i = 0;
    foreach( $emails as $email ){
        if( $i != 0 )
            $bcc .= \', \';
        $bcc .= $email;
        $i = 1;
    }

    $headers[] = $bcc;
    wp_mail( \'[email protected]\', \'New entry!\', $body, $headers );
?>

结束

相关推荐

如何在更新USER_EMAIL时更新BILLING_EMAIL

我正在努力实现user_email 和billing_email (woocommerce电子邮件的关键)。到目前为止,我的做法是,当客户编辑/更新其账单电子邮件地址时user_email 使用以下代码更新:add_action( \'woocommerce_customer_save_address\',\'isa_customer_save_address\', 10, 1); function isa_customer_save_address() { globa