本文實例講述了如何修改WordPress新用戶注冊郵件內容,因為系統發送的郵件是純文本類型的,頁面不太美觀,又沒有辦法發送自定義的HTML格式的郵件,將修改方法分享給大家供大家參考。具體方法如下:
最簡單的辦法
方法一、直接手動修改:
修改wordpresswp-includes目錄的pluggable.php,中的這段:
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "";
$message .= wp_login_url() . "";
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
例如改為如下代碼:
$message .= sprintf(__('Username: %s'), $user_login) . "rn";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn";
$message .= wp_login_url() . "rn";
$message .= sprintf(__('賬號需進一步審核才可以登入,請通知網站管理員')) . "rn";
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
方法二:
我們在當前主題的functions.php中加入重新定義的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> 有新用戶注冊。
用戶名:' . $user_login . '
Email:' . $user_email . '
如果您不是 <strong>' . $blogname . '</strong> 的管理員,請直接忽略本郵件!</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 ( emptyempty($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> 注冊一個帳號。
用戶名:' . $user_login . '
登錄密碼:' . $plaintext_pass . '
登錄網址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>
如果您沒有在 <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;
中間的$message中的內容你自己愛怎么寫就怎么寫吧.
希望本文所述對大家的WordPress建站有所幫助。