本文章來(lái)給大家介紹如何修改WordPress新用戶(hù)注冊(cè)郵件內(nèi)容,因?yàn)橄到y(tǒng)發(fā)送的郵件是純文本類(lèi)型的,頁(yè)面不太美觀,有沒(méi)有辦法發(fā)送自定義的HTML格式的郵件,有需要的朋友可參考.
最簡(jiǎn)單的辦法
一、直接手動(dòng)修改
修改wordpresswp-includes目錄的pluggable.php,中的這段:
- $message = sprintf(__('Username: %s'), $user_login) . "";
- $message .= sprintf(__('Password: %s'), $plaintext_pass) . "";
- $message .= wp_login_url() . "";
- wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
例如改為如下代碼:
- $message .= sprintf(__('歡迎加入***網(wǎng)')) . "rn";
- $message .= sprintf(__('Username: %s'), $user_login) . "rn";
- $message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn";
- $message .= wp_login_url() . "rn";
- $message .= sprintf(__('賬號(hào)需進(jìn)一步審核才可以登入,請(qǐng)通知網(wǎng)站管理員')) . "rn";
- wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
方法二
我們?cè)诋?dāng)前主題的functions.php中加入重新定義的wp_new_user_notification函數(shù)即可,下面是一個(gè)示例,可以根據(jù)自己的需求進(jìn)行修改:
- 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);
- // 獲取博客名稱(chēng)
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
- // 給管理員發(fā)送的郵件內(nèi)容,這里是HTML格式
- $message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用戶(hù)注冊(cè)</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;">您的網(wǎng)站 <strong>' . $blogname . '</strong> 有新用戶(hù)注冊(cè)。<br />用戶(hù)名:' . $user_login . '<br />Email:' . $user_email . '<br /><br />如果您不是 <strong>' . $blogname . '</strong> 的管理員,請(qǐng)直接忽略本郵件!</div></td></tr></table></td></tr></table></div></body></html>';
- // 給網(wǎng)站管理員發(fā)送郵件
- $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;
- // 你可以在此修改發(fā)送給新用戶(hù)的通知Email,這里是HTML格式
- $message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用戶(hù)注冊(cè)</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;">您剛剛在網(wǎng)站 <strong>' . $blogname . '</strong> 注冊(cè)一個(gè)帳號(hào)。<br />用戶(hù)名:' . $user_login . '<br />登錄密碼:' . $plaintext_pass . '<br />登錄網(wǎng)址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a><br /><br />如果您沒(méi)有在 <strong>'. $blogname . '</strong> 注冊(cè)過(guò)任何信息,請(qǐng)直接忽略本郵件!</div></td></tr></table></td></tr></table></div></body></html>';
- // sprintf(__('[%s] Your username and password'), $blogname) 為郵件標(biāo)題
- wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers);
- }
- endif;
中間的$message中的內(nèi)容你自己愛(ài)怎么寫(xiě)就怎么寫(xiě)吧.
新聞熱點(diǎn)
疑難解答
圖片精選