dounielong7728 2015-01-30 04:59
浏览 33

用户注册和激活电子邮件的自定义形式

I have implemented a custom login and registration form in WP as mentioned here. User can now register but can not login until admin approves that user from backend.

I need to implement admin notification email for new user registration as well as user notification email admin approves it from backend. I have tried below code in my registration form to send email but that does not seem to work. Moreover the standard email keeps sending.

/ Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
    function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
        $user = new WP_User($user_id);

        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);

        $message  = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "

";
        $message .= sprintf(__('Username: %s'), $user_login) . "

";
        $message .= sprintf(__('E-mail: %s'), $user_email) . "
";

        @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);

        if ( empty($plaintext_pass) )
            return;

        $message  = __('Hi there,') . "

";
        $message .= sprintf(__("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "

";
        $message .= wp_login_url() . "
";
        $message .= sprintf(__('Username: %s'), $user_login) . "
";
        $message .= sprintf(__('Password: %s'), $plaintext_pass) . "

";
        $message .= sprintf(__('If you have any problems, please contact me at %s.'), get_option('admin_email')) . "

";
        $message .= __('Adios!');

        wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);

    }
}

For user registration approval I am using this plugin.

How can I send email when user registers using my custom form and notify user when admin approves.

  • 写回答

1条回答 默认 最新

  • dos71253 2015-01-30 07:45
    关注

    You can set the content for email to be sent out to user on new registration on the settings page of WP Approve User plugin. Settings for this plugin is available under Settings menu in WordPress dashboard. Adding content there will do the job sending emails to user after their registration is approved.

    If you want to send out emails to Administrator after registration is approved, then you can write a code on the hook wpau_approve. This Hook accepts user id as the parameter.

    So you can write something like this:

    add_action ('wpau_approve' , 'send_mail_to_admin_post_approval', 10, 1);
    
    /*
     * Sends email to Administrator after user registration is approved
     * 
     * @param int $user_id User id of user whose registration is just approved
     */
    function send_mail_to_admin_post_approval($user_id) {
    
             $user = new WP_User($user_id);
    
            $user_login = stripslashes($user->user_login);
            $user_email = stripslashes($user->user_email);
    
            $message  = sprintf(__('New user registration on your blog %s:'), get_option('blogname')) . "
    
    ";
            $message .= sprintf(__('Username: %s'), $user_login) . "
    
    ";
            $message .= sprintf(__('E-mail: %s'), $user_email) . "
    ";
    
            @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
    }
    

    If even after adding above code in your plugin or theme's functions.php file mails are not going, then we would recommend to install the plugin Email Log. After installing that plugin you can view list of all emails triggered by wp_mail function on the page named 'Email Log' under 'Tools' menu in WordPress dashobard. If you see that, your email is being triggered by wp_mail and is not being received by recipients, then this might be issue with your SMTP settings.

    You might have to enable or install SMTP software on your server. If you do not have access to it, install WP Mail SMTP plugin and configure it. If WP Mail SMTP plugin is configured correctly, recipients should be able to receive emails which are triggered by wp_mail function after configuring the plugin.

    Hope this helps :)

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab