Use phpmailer to send emails and implement the code for the forgotten password search function. Friends in need can refer to it.
Achieve the following functions: 1. Follow the email retrieval link to enter the password reset operation page. Valid only once within a week 2. Reset password (you can also send the password to log in directly) 1. Generate email to retrieve email <?php $subject = " 重设密码(请勿回复此邮件)"; $auth = authcode($use_id . $account . $email, 'ENCODE', 'safeEmail', 3600 * 24 * 7); $url = "http://" . $_SERVER["HTTP_HOST"] . "/Main.php?do=userManage&method=ResetPass&u=" . $use_id . "&auth=" . $auth; $body = " 尊敬的用户: <br> 您好!<br> 根据您于 [" . date('Y-m-d H:m:s') . "] 提交的请求,本邮件将引导您重新设置 [" . $account . "] 的帐号密码。 如果您确认本次“重新设置密码”的请求是您自己提交的,请点这里完成重设操作(本链接仅一周内、一次有效 )。 如果上面的链接无法点击,您也可以复制以下链接,粘贴到您浏览器的地址栏内,然后按“回车”键打开重设机密问题页面设置新的机密问题和答案: {$url} 如果您在以上时间点没有提交过“重新设置密码”的请求,则有可能是您机密问题的答案已经泄露,有恶意用户正在试图窃取您的帐号!"; sendMail($subject, $body, $address); function sendMail($subject, $body, $address) { $mail = new PHPMailer(); $mail->CharSet ='utf-8'; $mail->IsHTML(true); // 设置邮件格式为 HTML $mail->IsSendmail(); //使用LINUX SENDMAIL发送邮件 $mail->Host = WEB_SITE_HOST; // specify main and backup server $mail->SMTPAuth = true; // 设置为安全验证方式 $mail->SetLanguage('en',PATH_CLASS.'/phpmailer/language/'); $mail->From = MAIL_SENDER; $mail->FromName = "service"; $mail->AddAddress($address); //收件人地址 $mail->WordWrap = 50; // set word wrap to 50 characters $mail->Subject = $subject; $mail->Body = daddslashes($body, 1); $result = $mail->Send(); if (!$result) { echo $mail->ErrorInfo; } $mail->SmtpClose(); return $result; } //邮件链接有效性检查 function ResetPass($mapping, $form, &$request, &$response) { $use_id = $request->getParameter('u'); $user = $this->delegate->getUserInfo_ById($use_id); $o_mail = $user['email']; $o_account = $user['account']; $auth = $request->getParameter('auth'); $auth = authcode($auth, 'DECODE', 'safeEmail'); $n_auth = $use_id . $o_account . $o_mail; $a = false; if ($n_auth == $auth) { $a = true; } $form->setEditUser($user); if ($a) { //有效 return $mapping->findForwardConfig('resetpwd'); } } ?> Copy after login class.phpmailer.php line 332 recursive call, mass mailing <?php public function AddMutieAddress($arrAddress){ if (is_array($arrAddress)){ foreach($arrAddress as $key=>$value){ $this->AddMutieAddress($value); } }else{ $this->AddAddress($arrAddress); } } ?> Copy after login First of all, gmail failed to use SMTPSecure=ssl. Solution to missing HTML styles sent by phpmailer: Styles with paths cannot be used to be defined using |