WordPress給咱們提供了一個可供插件又一次定義的新用戶郵件通知函數 wp_new_user_notification(),假設你不喜歡這個函數發送的郵件。咱們可以又一次定義這個函數的內容,以達到咱們本身定義的需求。php
WordPress定義的這個函數內容是這樣子的:html
if ( !function_exists('wp_new_user_notification') ) : /** * Notify the blog admin of a new user, normally via email. * * @since 2.0 * * @param int $user_id User ID * @param string $plaintext_pass Optional. The user's plaintext password */ function wp_new_user_notification($user_id, $plaintext_pass = '') { $user = get_userdata( $user_id ); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $message = sprintf(__('New user registration on your site %s:'), $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'), $blogname), $message); if ( empty($plaintext_pass) ) return; $message = sprintf(__('Username: %s'), $user_login) . "\r\n"; $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n"; $message .= wp_login_url() . "\r\n"; wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message); } endif;
咱們可以新建一個"插件",又一次定義的wp_new_user_notification函數定義的郵件內容就能夠。咱們在wp-content/plugins/文件夾下。新建一個文本文件命名爲new-user-notification.php,插入下面代碼。保存。而後在後臺啓動插件new-user-notification就能夠:wordpress
<?php /* Plugin Name: new-user-notification Description:又一次定義發送郵件的內容和格式 Version: 1.0 */ if ( !function_exists('wp_new_user_notification') ) : /** * Notify the blog admin of a new user, normally via email. * * @since 2.0 * * @param int $user_id User ID * @param string $plaintext_pass Optional. The user's plaintext password */ function wp_new_user_notification($user_id, $plaintext_pass = '') { $user = get_userdata( $user_id ); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); // 獲取博客名稱 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // 給管理員發送的郵件內容,這裏是HTML格式 $message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用戶註冊</title></head><body><div align="center"><table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"><tr><td style="padding:0;"><table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"><tr><td style="line-height:2;font-size:12px;">您的站點 <strong>' . $blogname . '</strong> 有新用戶註冊。<br />用戶名:' . $user_login . '<br />Email:' . $user_email . '<br /><br />假設您不是 <strong>' . $blogname . '</strong> 的管理員,請直接忽略本郵件!以上代碼僅僅是一個演示樣例,可以依據本身的需求進行改動。至於HTML郵件該怎麼寫,什麼樣的郵件格式美麗。這些就本身琢磨吧。</div></td></tr></table></td></tr></table></div></body></html>'; // 給站點管理員發送郵件 $message_headers = "Content-Type: text/html; charset=\"utf-8\"\n"; @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message, $message_headers); if ( empty($plaintext_pass) ) return; // 你可以在此改動發送給新用戶的通知Email,這裏是HTML格式 $message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用戶註冊</title></head><body><div align="center"><table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"><tr><td style="padding:0;"><table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"><tr><td style="line-height:2;font-size:12px;">您剛剛在站點 <strong>' . $blogname . '</strong> 註冊一個賬號。<br />用戶名:' . $user_login . '<br />登錄password:' . $plaintext_pass . '<br />登陸網址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a><br /><br />假設您沒有在 <strong>'. $blogname . '</strong> 註冊過不論什麼信息,請直接忽略本郵件!</div></td></tr></table></td></tr></table></div></body></html>'; // sprintf(__('[%s] Your username and password'), $blogname) 爲郵件標題 wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers); } endif; ?函數
>post