如何通过在mysql php中发送电子邮件来更新忘记密码 [英] How to update the forgotpassword by sending an email in mysql php

查看:155
本文介绍了如何通过在mysql php中发送电子邮件来更新忘记密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册表单,如果我点击忘记密码我正在收到邮件,如果我点击该链接它正在重定向到changepassword页面在这里我无法更新特定用户的密码。这是我的代码。发送忘记密码邮件时可以发送隐藏值的确认码



发送邮件:从这段代码我将收到电子邮件。

  $ email = $ _ POST ['email']; 

if($ _ POST ['submit'] =='Send')

{

$ query =select * from registered where email = '$电子邮件';

$ result = mysql_query($ query)or die(error);

if(mysql_num_rows($ result))

{

$ to = $ _POST ['email'];

$ from。='mail@gmail.com'。 \r\\\
\r\\\
;

$ subject =密码更改链接在这里;

$ message。=点击此链接更改密码\r\\\
;

$ message。=http://website.com/accounting/changepassword.php?email=$email;

$ success = mail($ to,$ subject,$ message);

echo忘记密码链接已发送到您的电子邮件。检查您的电子邮件以更改您的密码;

}

其他

{

回显此用户不存在此电子邮件ID;

}

}

链接:点击此链接更改密码
http://website.com/accounting/ changepassword.php?email=mail@gmail.com

如果我点击该链接,它将重定向到 forgetten.php 页面,我的代码是



但是我无法更新密码,任何人都可以帮我。如果我点击该链接,它将从这里重定向到该页面,它将changepassword.php



Changepassword.php

 < form method =POSTaction =togotten.phpid =myform> 
< input type ='hidden'value =<?php echo $ _GET ['email'];?>名称=邮件>
< div class =form-group>
< label for =psw>< span class =glyphicon>< / span>密码和LT; /标签>
< input id =passwordclass =form-controltype =passwordname =passwordplaceholder =在此输入密码必需/>
< / div>
< div class =form-group>
< label for =rpsw>< span class =glyphicon>< / span>确认密码< / label>
< input id =repasswordclass =form-controltype =passwordname =repasswordplaceholder =重新输入密码在这里必需/>
< / div>
< button type =submitclass =btn btn-success btn-block>< span class =glyphicon glyphicon-off>< / span>创建新密码< / button>



forgetten.php代码: / p>

 <?php 

$ connection = mysql_connect(localhost,root )或死(mysql_error());

$ db = mysql_select_db(accounting,$ connection);

$ email = $ _ POST ['email'];

$ password = $ _ POST ['password'];

$ repassword = $ _ POST ['repassword'];

$ sql1 =SELECT * FROM registered WHERE email ='$ email';

$ result1 = mysql_query($ sql1);

$ query = mysql_query(update registered SET password ='$ password',repassword ='$ repassword'WHERE email ='$ email');

if($ query)

{

$ to = $ _POST ['email'];

$ from。='mail@gmail.com'。 \r\\\
\r\\\
;

$ subject =密码已更改;

$ message。=您的密码已成功更改。\r\\\
;

$ success = mail($ to,$ subject,$ message);

echo密码已成功更改;

}

else {
echoInsertion Falied;
}
?>


解决方案

changepassword.php / p>


  1. AND 替换为 密码& repassword

  2. 删除'在coloumn名称电子邮件

  3. 'email'= $ result1 更改为 email ='$ email'

更改

  $ query = mysql_query(update registered SET password ='$ password'AND repassword ='$ repassword'WHERE'email'= $ result1); 

  $ query = mysql_query(update registered SET password ='$ password',repassword ='$ repassword'WHERE email ='$ email'); 

用户需求



由于您正在传递电子邮件至 changepassword.php
您必须为电子邮件创建一个隐藏字段,这将被提交到忘记密码。 php 页面。



检查数据库连接。并且,交叉检查所有的列名是否正确写入。



使用此代码。



ChangePassword.php

 < form method =POSTaction =togotten.phpid = myForm会 > 
< input type ='hidden'value =<?php echo $ _GET ['email'];?>名称=邮件>
< div class =form-group>
< label for =psw>< span class =glyphicon>< / span>密码和LT; /标签>
< input id =passwordclass =form-controltype =passwordname =passwordplaceholder =在此输入密码必需/>
< / div>
< div class =form-group>
< label for =rpsw>< span class =glyphicon>< / span>确认密码< / label>
< input id =repasswordclass =form-controltype =passwordname =repasswordplaceholder =重新输入密码在这里必需/>
< / div>
< button type =submitclass =btn btn-success btn-block>< span class =glyphicon glyphicon-off>< / span>创建新密码< / button>
< / form>

忘记.php

 < ;? 
$ connection = mysql_connect(localhost,root,)或die(mysql_error());
$ db = mysql_select_db(db_name,$ connection);

$ email = $ _ POST ['email'];
$ password = $ _ POST ['password'];
$ repassword = $ _ POST ['repassword'];

$ sql1 =SELECT * FROM registered WHERE email ='$ email';
$ result1 = mysql_query($ sql1);

$ query = mysql_query(update registered SET password ='$ password',repassword ='$ repassword'WHERE email ='$ email');

if($ query)
{
$ to = $ email;
$ from ='mail@gmail.com';
$ subject =密码已更改;
$ message。=您的密码已成功更改。
$ success = mail($ to,$ subject,$ message);
echo密码已成功更改;
}
?>


Hi I have a registration form if I click on forgot password I am getting mail if I click on that link it is redirecting to changepassword page here I am not able to update the password for a particular user. Here is my code.Is it possible to send confirmcode in hidden value while sending forgot password mail

Sending mail:From this code I will be getting email.

$email=$_POST['email'];

if($_POST['submit']=='Send')

{

$query="select * from registered where email='$email'"; 

$result=mysql_query($query) or die(error);

if(mysql_num_rows($result))

{

$to = $_POST['email'];

$from .= 'mail@gmail.com' . "\r\n\r\n";

$subject="Password Change link here";

$message.="Click on this link to change your password \r\n";

$message.="http://website.com/accounting/changepassword.php?email=$email";

$success = mail($to, $subject, $message);

echo "Forgot Password link has been sent to your email.Check your email to change your password";

}

else

{

echo "No user exist with this email id";

}

}

link: Click on this link to change your password
http://website.com/accounting/changepassword.php?email=mail@gmail.com

If I click on that link it will redirect to forgetten.php page and my code is

But I am not able to update the password can anyone help me this. If i click on that link it will redirect to this page from here it will changepassword.php

Changepassword.php

<form method="POST" action="forgotten.php" id="myform">
<input type='hidden' value="<?php echo $_GET['email'];?>" name='email'>
<div class="form-group">
<label for="psw"><span class="glyphicon"></span> Password</label>
<input id="password" class="form-control" type="password" name="password" placeholder="Enter password here" required/>
</div>
<div class="form-group">
<label for="rpsw"><span class="glyphicon"></span>Confirm Password</label>
<input id="repassword" class="form-control" type="password" name="repassword" placeholder="Retype password here" required/>
</div>
<button type="submit"  class="btn btn-success btn-block"><span class="glyphicon glyphicon-off"></span> Create New Password</button>

forgetten.php code:

    <?php

    $connection = mysql_connect("localhost", "root", "account") or       die(mysql_error());

  $db = mysql_select_db("accounting", $connection);

  $email=$_POST['email'];

  $password=$_POST['password'];

  $repassword=$_POST['repassword'];

  $sql1="SELECT * FROM registered WHERE email ='$email'";

  $result1=mysql_query($sql1);

  $query = mysql_query("update registered SET password = '$password', repassword ='$repassword' WHERE email='$email'");

 if($query)

 {

 $to = $_POST['email'];

 $from .= 'mail@gmail.com' . "\r\n\r\n";

 $subject="Password Changed";

 $message.="your password has been changed successfully. \r\n";     

 $success = mail($to, $subject, $message);

 echo "Password has been changed successfully";

 }

    else{
        echo "Insertion Falied";
    }
?>

解决方案

changepassword.php

  1. Replace AND with , between password & repassword.
  2. Remove ' in coloumn name email.
  3. Change 'email'=$result1 to email='$email'

Change

$query = mysql_query("update registered SET password = '$password' AND repassword ='$repassword' WHERE 'email'=$result1");

to

$query = mysql_query("update registered SET password = '$password', repassword ='$repassword' WHERE email='$email'");

For User's Requirement.

Since, you are passing email to changepassword.php. You have to create one hidden field for email, which will get submitted to forgottenpassword.php page.

Check your database connection. And, cross check whether all column name are written properly.

Use this code as it is.

ChangePassword.php

<form method="POST" action="forgotten.php" id="myform">
    <input type='hidden' value="<?php echo $_GET['email'];?>" name='email'>
    <div class="form-group">
    <label for="psw"><span class="glyphicon"></span> Password</label>
    <input id="password" class="form-control" type="password" name="password" placeholder="Enter password here" required/>
    </div>
    <div class="form-group">
    <label for="rpsw"><span class="glyphicon"></span>Confirm Password</label>
    <input id="repassword" class="form-control" type="password" name="repassword" placeholder="Retype password here" required/>
    </div>
    <button type="submit"  class="btn btn-success btn-block"><span class="glyphicon glyphicon-off"></span> Create New Password</button>
</form>

forgotten.php

<?
$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("db_name", $connection);

$email=$_POST['email'];
$password=$_POST['password'];
$repassword=$_POST['repassword']; 

$sql1="SELECT * FROM registered WHERE email ='$email'";
$result1=mysql_query($sql1);

$query = mysql_query("update registered SET password = '$password', repassword ='$repassword' WHERE email='$email'");

if($query)
{
    $to = $email;
    $from = 'mail@gmail.com';
    $subject="Password Changed";
    $message.="your password has been changed successfully. ";      
    $success = mail($to, $subject, $message);
    echo "Password has been changed successfully";
}
?>

这篇关于如何通过在mysql php中发送电子邮件来更新忘记密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆