[英]User registration and activation email in custom form
我實現了自定義登錄和注冊表格WP提到這里 。 用戶現在可以注冊,但無法登錄,直到管理員從后端批准該用戶。
我需要為新用戶注冊實施管理員通知電子郵件,並且用戶通知電子郵件管理員會從后端批准它。 我已經嘗試在注冊表格中使用以下代碼發送電子郵件,但這似乎不起作用。 此外,標准電子郵件不斷發送。
/ 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')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
if ( empty($plaintext_pass) )
return;
$message = __('Hi there,') . "\r\n\r\n";
$message .= sprintf(__("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
$message .= wp_login_url() . "\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n\r\n";
$message .= sprintf(__('If you have any problems, please contact me at %s.'), get_option('admin_email')) . "\r\n\r\n";
$message .= __('Adios!');
wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_option('blogname')), $message);
}
}
為了獲得用戶注冊批准,我正在使用此插件。
當用戶使用我的自定義表單注冊時如何發送電子郵件,並在管理員批准后通知用戶。
您可以在WP Approve User插件的設置頁面上的新注冊中設置要發送給用戶的電子郵件的內容。 此插件的設置位於WordPress儀表板的“設置”菜單下。 在用戶注冊被批准之后,在那里添加內容將完成向用戶發送電子郵件的工作。
如果要在批准注冊后向管理員發送電子郵件,則可以在鈎子wpau_approve
上編寫代碼。 該掛鈎接受用戶ID作為參數。
所以你可以這樣寫:
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')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
}
如果即使在您的插件或主題的functions.php文件中添加上述代碼后仍然無法發送郵件,那么我們建議您安裝插件Email Log 。 安裝該插件后,您可以在WordPress dashobard中“工具”菜單下名為“電子郵件日志”的頁面上查看由wp_mail函數觸發的所有電子郵件的列表。 如果您看到此消息,則說明您的電子郵件是由wp_mail觸發的,而收件人沒有收到該電子郵件,則SMTP設置可能有問題。
您可能必須在服務器上啟用或安裝SMTP軟件。 如果您無權訪問,請安裝WP Mail SMTP插件並進行配置。 如果WP Mail SMTP插件配置正確,則收件人在配置插件后應該能夠接收由wp_mail函數觸發的電子郵件。
希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.