寻找一些很好的选项来发送用户重置密码电子邮件 [英] Looking for a some good options to send users reset password emails
问题描述
我想在忘记密码时提醒用户重置密码时,向用户发送电子邮件。我知道这是有争议的,并正在寻找一些很好的选项/建议/方法/文章可供选择。
$ b $提示用户按下一个简单的脚本按下忘记密码链接b
$ Email = $ _POST ['email'];
$ success = false;
$ formError = false;
if(isset($ _ POST ['sub_forgot_pw'])){
if(empty($ _ POST ['email'])){
$ formError =true;
$ error =请输入您的电子邮件地址。;
} else {
$ to = $ Email;
$ subject =密码帮助;
$ message =要重置您的密码,请< a href ='http://www.blahblahblah.org'>点击此处< / a>< br />< br />做LIFE,< br />团队;
$ from =CysticLife< noreply@cysticlife.org>;
$ headers ='MIME-Version:1.0'。 \\\
;
$ headers。='Content-type:text / html; charset = iso-8859-1'。 \\\
;
$ headers。=From:$ from;
if(mail($ to,$ subject,$ message,$ headers)); {
$ success =true;
}
}
}
<解决方案
这是我的工作:
我有reset_password表。当有人要求重置时,他们通常会点击您网站上的忘记密码链接,输入他们注册的电子邮件并且系统会发送链接。
当然,您首先要了解用户是否已注册。通过选择电子邮件= $ _POST ['email']的用户。
如果它们存在,则创建一个随机生成的标记,如
$ token = md5($ _ POST ['email' ]。时间());
但是Buh Buh在下面的评论中表达过,您可能想要使用一些不那么明显的内容生成你的令牌。 crypt()可以接受salt模式(如果你喜欢的话)。
将请求(电子邮件和令牌)插入到reset_password表中,然后向它们发送一个链接,如
http://www.domain.com/resetpassword.php?token=<?php echo $ token; ?>
然后在那个文件中取$ _GET ['token']并用reset_password表。如果令牌有效,则向他们呈现一个要求输入新密码的表单。
提交后,选择具有与该令牌相关的电子邮件地址的用户并更新用户表。
I want to send emails to users when the forget their passwords that prompt them to reset their passwords. I know this is debatable and was looking for a few good options/suggestions/methods/articles to choose from.
I'm prompting users to press a 'forgot password' link with a simple script with the PHP portion doing this:
$Email = $_POST['email'];
$success = false;
$formError = false;
if(isset($_POST['sub_forgot_pw'])) {
if(empty($_POST['email'])) {
$formError = "true";
$error = "Please enter your e-mail address.";
}else{
$to = $Email;
$subject = "Password Help";
$message = "To reset your password, please <a href='http://www.blahblahblah.org'>Click here</a><br /><br />Do LIFE,<br /> The Team";
$from = "CysticLife <noreply@cysticlife.org>";
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= "From: $from";
if(mail($to, $subject, $message, $headers));{
$success = "true";
}
}
}
Here's what I do:
I have reset_password table. When someone asks for a reset, they usually click a link on your site that says "forgot password" where they enter their email they registered with and your system sends a link. Of course you begin with finding out if the user is registered at all. by selecting from users where email = $_POST['email']. If they exist, make a randomly generated token, like
$token = md5($_POST['email'].time());
But as Buh Buh expressed in the comment below, you may want to use something a little less obvious to generate your token. crypt() can accept a salt pattern if you like.
Insert the request (email and token) in the reset_password table, then you send them a link like
http://www.domain.com/resetpassword.php?token=<?php echo $token; ?>
Then in that file you take the $_GET['token'] and cross reference it with the reset_password table. If the token is valid, you present them with a form that asks for their new password. Upon submit, select the user with the email address related to that token and update the user table.
这篇关于寻找一些很好的选项来发送用户重置密码电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!