一直以来都没有注意到自己的博客不能注册,今天把注册的东西改了一下。我本地改好了,直接显示密码或者发送邮件都是可以的,上传服务器上就不行了,phpmailer,smtp发送邮件老是实败,根本原因是在国外连接国内的smtp服务器老是超时,提示unable to connect to smtp.163.com:25 (Connection timed out) ,搞得我很郁闷,我想如果是国内的服务器肯定是可以的,制作过程如下:
1,制作一个mail_fun.php
<?php
require_once( ABSPATH . 'wp-includes/class.phpmailer.php'); //包函邮件发送类
//邮件发送
function send_mail($frommail,$tomail,$subject,$body,$ccmail,$bccmail) {
$mail = new PHPMailer();
$mail->IsSMTP(); // 经smtp发送
$mail->Host = "smtp.163.com"; // SMTP 服务器
$mail->SMTPAuth = true; // 打开SMTP 认证
$mail->Username = "zhangyinghf@163.com"; // 用户名
$mail->Password = "************"; // 密码
$mail->From = $frommail; // 发信人
$mail->FromName = "海底苍鹰tank"; // 发信人别名
$mail->AddAddress($tomail); // 收信人
if(!empty($ccmail)){
$mail->AddCC($ccmail); // cc收信人
}
if(!empty($bccmail)){
$mail->AddCC($bccmail); // bcc收信人
}
$mail->WordWrap = 50;
$mail->IsHTML(true); // 以html方式发送
$mail->Subject = $subject; // 邮件标题
$mail->Body = $body; // 邮件内容
$mail->AltBody = "请使用HTML方式查看邮件。";
return $mail->Send();
}
?>
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找到下内容
wp_new_user_notification($user_id, $user_pass); //大约在281行
替换成以下内容
if(empty($_COOKIE['way'])){
send_mail("zhangyinghf@163.com",$user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
}else{
setcookie("user_login", $user_login,time()+1800);
setcookie("user_pass", $user_pass,time()+1800);
}
4,还是在wp-login.php里面找到$user_email = $_POST['user_email'];大约在422行,在下面添加
$way = $_POST['getpassword'];
if($way == 2){
setcookie("way", $way,time()+1800);
}else{
setcookie("way", "");
}
5,在wp-login.php的里面找到name="user_email",就是在填写email的下面加上一个选择是发邮件获得密码,还是直接显示获得密码
<p> <label><?php echo "获得密码的方式(默认通过邮件取得密码)" ?><br /> <input type="radio" name="getpassword" value="1" size="25" <?php echo $way==1?"checked":"";?> tabindex="20" />邮件方式获得<br> <input type="radio" name="getpassword" value="2" size="25" <?php echo $way==2?"checked":"";?> tabindex="20" />直接显示 </label> </p>
6,在wp-login.php里面找到isset($_GET['checkemail']) && 'registered' == $_GET['checkemail']大约在546行,将里面的
$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
替换成
if(!empty($_COOKIE['way'])){
$errors->add('registered',__('注册成功!<br/><br/>用户名:'.$_COOKIE['user_login'].'<br/>密码:'.$_COOKIE['user_pass'].'<br/>登录后修改密码'));
}else{
$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
}
7,在wp-settings.php里面找到define('WPINC', 'wp-includes');在其下面添加一行
require (ABSPATH . WPINC . '/mail_fun.php');
其实我用的wordpress里面,封装了class.phpmailer.php,我不想在原来的基础上改,因为将来升级的话,这些东西肯定会被盖掉的。
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/wordpress/915.html