多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > WordPress > WordPress修改新用戶注冊郵件內容教程

WordPress修改新用戶注冊郵件內容教程

來源:程序員人生   發布時間:2014-04-03 19:41:48 閱讀次數:3292次

有些開放用戶注冊功能的WordPress站點,可能有這么一項需求,就是用戶注冊成功后,系統會分別給網站管理員和新用戶發送一封通知郵件,給管理員發送的是新用戶的用戶名和Email,給剛剛注冊的新用戶發送的是他的用戶名和密碼。系統發送的郵件是純文本類型的,頁面不太美觀,有沒有辦法發送自定義的HTML格式的郵件呢?答案是可以的。

WordPress給我們提供了一個可供插件重新定義的新用戶郵件通知函數 wp_new_user_notification(),如果你不喜歡這個函數發送的郵件,我們可以重新定義這個函數的內容,以達到我們自定義的需求。

原函數

WordPress定義的這個函數內容是這樣子的:

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) . "";
$message .= sprintf(__('Username: %s'), $user_login) . "";
$message .= sprintf(__('E-mail: %s'), $user_email) . "";

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

if ( empty($plaintext_pass) )
return;

$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);

}
endif;

自定義郵件內容和格式

我們可以在原函數的基礎上,重新定義發送郵件的內容和格式,我們在當前主題的functions.php中加入重新定義的wp_new_user_notification函數即可,下面是一個示例,可以根據自己的需求進行修改:

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> 的管理員,請直接忽略本郵件!</div></td></tr></table></td></tr></table></div></body></html>';

// 給網站管理員發送郵件
$message_headers = "Content-Type: text/html; charset="utf-8"";
@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 />登錄密碼:' . $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;

至于HTML郵件該怎么寫,什么樣的郵件格式漂亮,這些就自己琢磨吧。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
為碼而活
積分:4237
15粉絲
7關注
欄目熱點
關閉
程序員人生
主站蜘蛛池模板: 国产欧美成人免费观看视频 | 一区二区三区四区五区 | 在线观看日韩欧美 | 图片区 日韩 欧美 亚洲 | 国产免费久久精品44 | 国产精品三区四区 | 免费视频网站在线观看 | 色永久| 欧美国产日韩在线播放 | 精品视频在线观看 | 亚洲国产天堂久久综合 | 综合毛片 | 欧美日本亚洲 | 欧美一级成人毛片视频 | 国产日韩欧美综合一区二区三区 | 最近中文字幕视频国语中文字幕 | 一区二区三区四区免费视频 | 亚洲人成亚洲人成在线观看 | 亚洲毛片在线看 | 欧美18性精品 | 成人动漫中文字幕 | 日本一区二区三区不卡视频中文字幕 | 一级做a爱免费观看视频 | 日本一区二区三区在线 视频观看免费 | 最近中文字幕2019免费版日本 | 久久ri精品高清一区二区三区 | 精品国产日韩亚洲一区91 | 精品一区二区三区四区五区 | 欧美色图一区 | 日本大片a | 日本免费www| 久久www免费人成看国产片 | 午夜免费啪视频观看网站 | 国产日韩欧美精品一区二区三区 | 边摸边吃奶边做娇喘视频 | 性色va| 免费性| 高清在线亚洲精品国产二区 | 青青草原国产在线视频 | 超清中文乱码精品字幕在线观看 | baoyu116.永久免费网站 |