wordpress注册发送邮件或者直接显示密码

张映 发表于 2010-07-13

分类目录: wordpress

标签:, , ,

一直以来都没有注意到自己的博客不能注册,今天把注册的东西改了一下。我本地改好了,直接显示密码或者发送邮件都是可以的,上传服务器上就不行了,phpmailer,smtp发送邮件老是实败,根本原因是在国外连接国内的smtp服务器老是超时,提示unable to connect to smtp.163.com:25 (Connection timed out) ,搞得我很郁闷,我想如果是国内的服务器肯定是可以的,制作过程如下:

1,制作一个mail_fun.php

  1. <?php  
  2. require_once( ABSPATH . 'wp-includes/class.phpmailer.php');    //包函邮件发送类  
  3. //邮件发送  
  4. function send_mail($frommail,$tomail,$subject,$body,$ccmail,$bccmail) {  
  5.  $mail = new PHPMailer();  
  6.  $mail->IsSMTP();                            // 经smtp发送  
  7.  $mail->Host     = "smtp.163.com";           // SMTP 服务器  
  8.  $mail->SMTPAuth = true;                     // 打开SMTP 认证  
  9.  $mail->Username = "zhangyinghf@163.com";    // 用户名  
  10.  $mail->Password = "************";          // 密码  
  11.  $mail->From     = $frommail;                  // 发信人  
  12.  $mail->FromName = "海底苍鹰tank";        // 发信人别名  
  13.  $mail->AddAddress($tomail);                 // 收信人  
  14.  if(!emptyempty($ccmail)){  
  15.  $mail->AddCC($ccmail);                    // cc收信人  
  16.  }  
  17.  if(!emptyempty($bccmail)){  
  18.  $mail->AddCC($bccmail);                   // bcc收信人  
  19.  }  
  20.  $mail->WordWrap = 50;  
  21.  $mail->IsHTML(true);                            // 以html方式发送  
  22.  $mail->Subject  = $subject;                 // 邮件标题  
  23.  $mail->Body     = $body;                    // 邮件内容  
  24.  $mail->AltBody  =  "请使用HTML方式查看邮件。";  
  25.  return $mail->Send();  
  26. }  
  27. ?>  

2,将mail_fun.php,class.mailer.php,class.smtp.php上传到wp-includes上面,class.mailer.php,class.smtp.php这二个文件,解压phpmailer的时候里面会有的

3,wp-login.php文件里面有个function名字是register_new_user找到下内容

  1. wp_new_user_notification($user_id$user_pass); //大约在281行  

替换成以下内容

  1. if(emptyempty($_COOKIE['way'])){  
  2. send_mail("zhangyinghf@163.com",$user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);  
  3. }else{  
  4. setcookie("user_login"$user_login,time()+1800);  
  5. setcookie("user_pass"$user_pass,time()+1800);  
  6. }  

4,还是在wp-login.php里面找到$user_email = $_POST['user_email'];大约在422行,在下面添加

  1. $way = $_POST['getpassword'];  
  2.   
  3.  if($way == 2){  
  4.  setcookie("way"$way,time()+1800);  
  5.  }else{  
  6.  setcookie("way""");  
  7.  }  

5,在wp-login.php的里面找到name="user_email",就是在填写email的下面加上一个选择是发邮件获得密码,还是直接显示获得密码

  1. <p>  
  2.  <label><?php echo "获得密码的方式(默认通过邮件取得密码)" ?><br />  
  3.  <input type="radio" name="getpassword"  value="1" size="25" <?php echo $way==1?"checked":"";?> tabindex="20" />邮件方式获得<br>  
  4.  <input type="radio" name="getpassword"  value="2" size="25" <?php echo $way==2?"checked":"";?> tabindex="20" />直接显示  
  5.  </label>  
  6.  </p>  

6,在wp-login.php里面找到isset($_GET['checkemail']) && 'registered' == $_GET['checkemail']大约在546行,将里面的

  1. $errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');  

替换成

  1. if(!emptyempty($_COOKIE['way'])){  
  2. $errors->add('registered',__('注册成功!<br/><br/>用户名:'.$_COOKIE['user_login'].'<br/>密码:'.$_COOKIE['user_pass'].'<br/>登录后修改密码'));  
  3. }else{  
  4. $errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');  
  5. }  

7,在wp-settings.php里面找到define('WPINC', 'wp-includes');在其下面添加一行

  1. require (ABSPATH . WPINC . '/mail_fun.php');  

其实我用的wordpress里面,封装了class.phpmailer.php,我不想在原来的基础上改,因为将来升级的话,这些东西肯定会被盖掉的。



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/wordpress/915.html