用于新用户注册的自定义管理员电子邮件

时间:2015-01-14 作者:David Pearce

我已经在网上搜寻这个小问题的解决方案,但我不断得到的结果告诉我如何定制通知电子邮件,而不是电子邮件地址。

我在WP设置中的管理员电子邮件地址为abc@xyz.tld这很好,但是所有新的用户注册我都想转到不同的电子邮件地址。

e、 g。

已注册新用户,电子邮件发送至def@hij.td

插件、主题等需要更新,所有电子邮件abc@xyz.tld

2 个回复
SO网友:krishna

是的,您可以使用wp\\U邮件功能更改电子邮件地址。你可以检查这个怎么做http://www.butlerblog.com/2011/07/14/changing-the-wp_mail-from-address-with-a-plugin/

使用此插件进行用户管理它支持新用户注册时的电子邮件地址https://wordpress.org/plugins/wp-members/

在函数中使用此代码。php文件。

function so174837_registration_email_alert( $user_id ) {
    $user    = get_userdata( $user_id );
    $email   = $user->user_email;
    $message = $email . \' has registered to your website.\';
    wp_mail( \'youremail@example.com\', \'New User registration\', $message );
}
add_action(\'user_register\', \'so174837_registration_email_alert\');

SO网友:butlerblog

我是在谷歌搜索一个特定的电子邮件问题时被引导到这篇文章的。有趣的是,发布的答案引用了我的一篇博客帖子和我的插件。这真是太棒了——除了我认为在这种情况下,这并不能真正回答OP。

问题是,给管理员的所有通知都需要转到指定的电子邮件地址,除了一个——新用户通知。

我的方法(前提是该过程是WP本地注册)是在wp_mail() (顺便说一句a filter at the end of the entire process).

我会使用该过滤器查看消息的内容,如果是发送给新用户通知的电子邮件,则使用该过滤器更改“收件人”地址。

在此示例中,将检查主题是否包含“新用户注册”,这是WP默认管理员通知电子邮件中主题行的一部分。如果是这种情况,则“收件人”电子邮件地址将更改为所需的地址。否则,所有其他情况都会原封不动地通过过滤器。

add_filter( \'wp_mail\', \'my_wp_mail_filter\' );
function my_wp_mail_filter( $args ) {
    // Check the message subject for a known string in the notification email.
    if ( strpos( $args[\'subject\'], \'New User Registration\' ) ) {
        // This is the notification email, so change the "to" address.
        $args[\'to\'] = \'def@hij.td\';
    }
    return $args;
}

结束