麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > CMS > Wordpress > 正文

Wordpress用戶注冊郵件內容自定義格式美化實例

2024-09-07 00:51:48
字體:
來源:轉載
供稿:網友

WordPress站點,新用戶注冊成功后,系統會分別給網站管理員和新用戶發送郵件通知,默認發送的郵件不太美觀,現在我們來講解一下如何自定義郵件內容的html格式.

WordPress提供了一個可供插件重新定義的新用戶郵件通知函數 wp_new_user_notification(),現在我們來重新定義這個函數的內容,來美化我們的郵件內容格式.

原函數函數內容如下:

  1. if ( !function_exists('wp_new_user_notification') ) : 
  2. /** 
  3.  * Notify the blog admin of a new user, normally via email. 
  4.  * 
  5.  * @since 2.0 
  6.  * 
  7.  * @param int $user_id User ID 
  8.  * @param string $plaintext_pass Optional. The user's plaintext password 
  9.  */ 
  10. function wp_new_user_notification($user_id$plaintext_pass = '') { 
  11.     $user = get_userdata( $user_id ); 
  12.  
  13.     $user_login = stripslashes($user->user_login); 
  14.     $user_email = stripslashes($user->user_email); 
  15.  
  16.     // The blogname option is escaped with esc_html on the way into the database in sanitize_option 
  17.     // we want to reverse this for the plain text arena of emails. 
  18.     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
  19.  
  20.     $message  = sprintf(__('New user registration on your site %s:'), $blogname) . "rnrn"
  21.     $message .= sprintf(__('Username: %s'), $user_login) . "rnrn"
  22.     $message .= sprintf(__('E-mail: %s'), $user_email) . "rn"
  23.  
  24.     @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message); 
  25.  
  26.     if ( emptyempty($plaintext_pass) ) 
  27.         return
  28. //開源軟件:Vevb.com 
  29.     $message  = sprintf(__('Username: %s'), $user_login) . "rn"
  30.     $message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn"
  31.     $message .= wp_login_url() . "rn"
  32.  
  33.     wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message); 
  34.  
  35. endif

自定義郵件內容和格式

我們可以新建一個"插件",重新定義的wp_new_user_notification函數定義的郵件內容即可,我們在wp-content/plugins/目錄下,新建一個文本文件命名為new-user-notification.php,插入以下代碼,保存,然后在后臺啟動插件new-user-notification即可,代碼如下:

  1. <?php 
  2. /* 
  3.   Plugin Name: new-user-notification 
  4.   Description:重新定義發送郵件的內容和格式 
  5.   Version: 1.0 
  6.  */ 
  7.  
  8. if ( !function_exists('wp_new_user_notification') ) : 
  9. /** 
  10.  * Notify the blog admin of a new user, normally via email. 
  11.  * 
  12.  * @since 2.0 
  13.  * 
  14.  * @param int $user_id User ID 
  15.  * @param string $plaintext_pass Optional. The user's plaintext password 
  16.  */ 
  17. function wp_new_user_notification($user_id$plaintext_pass = '') { 
  18.     $user = get_userdata( $user_id ); 
  19.  
  20.     $user_login = stripslashes($user->user_login); 
  21.     $user_email = stripslashes($user->user_email); 
  22.  
  23.     // 獲取博客名稱 
  24.     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); 
  25.  
  26.     // 給管理員發送的郵件內容,這里是HTML格式 
  27.     $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>'
  28.  
  29.     // 給網站管理員發送郵件 
  30.     $message_headers = "Content-Type: text/html; charset="utf-8"n"
  31.     @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message$message_headers); 
  32.  
  33.     if ( emptyempty($plaintext_pass) ) 
  34.         return
  35.     
  36.     // 你可以在此修改發送給新用戶的通知Email,這里是HTML格式 
  37.     $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>'
  38.  
  39.     // sprintf(__('[%s] Your username and password'), $blogname) 為郵件標題 
  40.     wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message$message_headers); 
  41. endif
  42. ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩av在线播放一区 | 一级黄色大片在线观看 | 成人国产精品色哟哟 | 国产精品视频自拍 | 日本一区二区不卡高清 | 成人国产视频在线观看 | 国产精品视频一区二区三区四 | 国产毛片在线看 | 午夜激情视频免费 | 深夜毛片免费看 | 国产日产精品久久久久快鸭 | 韩国精品一区二区三区四区五区 | 国产精品1区2区在线观看 | h视频免费在线观看 | 国产电影精品久久 | 99爱视频在线 | 国产免费一区 | 香蕉视频网站在线观看 | 久久久国产精品视频 | 久久久精品视 | av电影免费播放 | av免费在线免费观看 | 亚洲国产高清一区 | 国产人成精品综合欧美成人 | 精品国产一区二区亚洲人成毛片 | av在线免费观看播放 | 亚洲网站免费观看 | 亚洲视频在线网 | 日韩黄色片网站 | 欧美性色黄大片www 成人免费网站在线观看 | 欧美一级片 在线播放 | 黄片毛片一级 | 国产成人精品一区二区视频免费 | av老司机久久 | 免费的毛片 | 精品视频一区二区三区四区 | 天天看天天摸天天操 | 亚洲视屏在线 | 小视频在线看 | 亚洲精久 | 黄色特级毛片 |