实现发布新文章Email通知注册用户

11664993_152755345136_2
QQ邮箱订阅中有这样一个功能:在读者订阅博客后将每天汇总该博客更新信息,并发送至QQ邮箱里。我们可以效仿此法,达到同等推广效果。这样一来,网站更新了什么内容即可直接调用信息,批量发送新文章内容至 Email 通知自己的用户。

在服务器开启 Mail 函数情况下,添加以下代码至 Functions.php:

  1. function newPostNotify($post_ID) {  
  2.      if( wp_is_post_revision($post_ID) ) return;  
  3.    
  4.      global $wpdb;  
  5.      $get_post_info = get_post($post_ID);  
  6.      if ( $get_post_info->post_status == ‘publish’ && $_POST[‘original_post_status’] != ‘publish’ ) {  
  7.          // 读数据库,获取所有用户的email  
  8.          $wp_user_email = $wpdb->get_results(“SELECT DISTINCT user_email FROM $wpdb->users”);  
  9.    
  10.          // 依次给每个Email发邮件  
  11.         foreach ( $wp_user_email as $email ) {  
  12.              // 邮件标题:xx博客有新文章  
  13.             $subject = ‘xx博客有新文章’;  
  14.    
  15.              // 邮件内容:新文章网址:+ URL  
  16.              $message = ‘新文章网址:’ . get_permalink($post_ID);  
  17.    
  18.              // 发邮件  
  19.             wp_mail($email->user_email, $subject, $message);   
  20.          }  
  21.      }  
  22. }  
  23.    
  24. // 钩子,一旦WordPress有新文章发布或文章被修改即刻执行newPostNotify函数  
  25. add_action(‘publish_post’, ‘newPostNotify’);  

WordPress 实现用户使用Email地址登录

90b1OOOPICce
对于忘记注册的用户名这种情况,可谓再常见不过了……幸运的是,您可以在登录界面增加一个“使用Email登录”的选项,这样,我们可爱的用户应该不会再为登录不上 WordPress 而苦恼了吧?

代码添加 Email 登录功能,添加以下代码至 Functions.php:

  1. //remove wordpress authentication  
  2. remove_filter(‘authenticate’, ‘wp_authenticate_username_password’, 20);  
  3.    
  4. add_filter(‘authenticate’, function($user, $email, $password){  
  5.    
  6.     //Check for empty fields  
  7.         if(empty($email) || empty ($password)){          
  8.             //create new error object and add errors to it.  
  9.             $error = new WP_Error();  
  10.    
  11.             if(empty($email)){ //No email  
  12.                 $error->add(’empty_username’, __(‘<strong>ERROR</strong>: Email field is empty.’));  
  13.             }  
  14.             else if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ //Invalid Email  
  15.                 $error->add(‘invalid_username’, __(‘<strong>ERROR</strong>: Email is invalid.’));  
  16.             }  
  17.    
  18.             if(empty($password)){ //No password  
  19.                 $error->add(’empty_password’, __(‘<strong>ERROR</strong>: Password field is empty.’));  
  20.             }  
  21.    
  22.             return $error;  
  23.         }  
  24.    
  25.         //Check if user exists in WordPress database  
  26.         $user = get_user_by(’email’, $email);  
  27.    
  28.         //bad email  
  29.         if(!$user){  
  30.             $error = new WP_Error();  
  31.             $error->add(‘invalid’, __(‘<strong>ERROR</strong>: Either the email or password you entered is invalid.’));  
  32.             return $error;  
  33.         }  
  34.         else//check password  
  35.             if(!wp_check_password($password, $user->user_pass, $user->ID)){ //bad password  
  36.                 $error = new WP_Error();  
  37.                 $error->add(‘invalid’, __(‘<strong>ERROR</strong>: Either the email or password you entered is invalid.’));  
  38.                 return $error;  
  39.             }else{  
  40.                 return $user; //passed  
  41.             }  
  42.         }  
  43. }, 203);  

Zoho Mail 取代 Google Apps 可自訂網址的免費 Email 信箱(5 GB 容量)

較早期 Google Apps 還是免費服務時,許多站長會以自己的網域名稱去 Google Apps 申請信箱,就可以透過公司、組織或個人的網域名稱來接收郵件。Google 提供的信箱不但容量很大,而且穩定,當時微軟也有提供讓使用者自訂網址的服務,可惜後來 Google Apps 和微軟不再開放使用者免費申請,現在如果要有個自訂網址的 Email 信箱,就必須尋找其他替代服務,而 Zoho Mail 就是其中一個不錯的選擇。

Zoho Mail 是 Zoho 旗下的一個免費信箱服務,大家可能對於 Zoho 比較不熟悉,這是一家提供線上應用的服務商,有許多不錯的的辦公室工具可以免費使用,包括表單處理、免費信箱、專案管理、試算表、文書處理等,它的 Mail 服務正好有提供自訂網址功能,免費方案最多可以開啟 10 個帳戶,每個帳戶的信箱容量為 5 GB。

Zoho Mail 支援 POP、SMTP、IMAP 收發郵件,本身也有提供簡体中文介面,介面還算簡單、容易操作。如果使用網頁收信不習慣,也可以透過郵件軟體,或從其他網站、App 來收取郵件。若你不想額外付費來租用自訂網域名稱的信箱服務,那麼不妨試試看本文介紹的 Zoho Mail 吧!

網站名稱:Zoho Mail

網站鏈結:https://www.zoho.com/mail/