php sendemail to recover password

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
amici come ben sapete sto lavorando a un sito web php.

Allora dopo aver fatto tutte le funzioni di registrazione accesso etc, sto lavorando sulla procedura di recupero password.

Ho creato nella main page un link che apre una finesta modale dove inserendo la mail verificando che essa esista mando una mail con un link

la form è questa:

HTML:
<form action ="sendmailwebsite.php" method="POST">

            <img id="image" src="immagini/immaginiprova/background.png" />
            <p id="text">
                <img id="password_forgot" src="immagini/forgot.png" style="width:90%; margin-left:5%;"/>
                <br>
                <br>

                <?php echo $error ?>
                <label for="email_address" style="font-family: foo; font-size:40px; margin-left: 10%;">Email:</label>
                <br>
                <br>
                <input type="text" name="email-recovery" id="email-recovery" class="textField" style="width:620px; height:42px;  margin-left: 10%; font-size:25px; font-family: 'Fontdiner Swanky', cursive;"/>
                <br>
                <br>
                <!--<img id="ok" src="immagini/ok.png"  style="width:30%;margin-top:20%; margin-left: 35%;" />-->
                <input type="image" value="send" src="immagini/ok.png" alt="Submit" style="width:30%; float:right;margin-top: 20%; margin-right:35%;"
            </p>
            </form>


come vedete richiama un sendemail.php che vi posto ora

Codice:
<?php
/**
* Created by PhpStorm.
* User: Christian
* Date: 07/06/2017
* Time: 10:51
*/

require_once('scripts/php_scripts/mail_prova/class.phpmailer.php');
require_once('scripts/php_scripts/mail_prova/class.smtp.php');
require_once('scripts/php_scripts/mail_prova/class.pop3.php');
require_once('scripts/php_scripts/mail_prova/class.phpmaileroauthgoogle.php');
require_once('scripts/php_scripts/mail_prova/class.phpmaileroauth.php');
require_once('scripts/php_scripts/dbconnect.php');

$error = "";
$db = new dbconnect;

$address = $_POST['email-recovery'];

$existing = $db->existingemail($address);
if($existing == "Valid Email") {


    $mail = new PHPMailer();
    $uniqidStr = md5(uniqid(mt_rand()));

    //$resetPassLink = 'https://guesswhothegame/resetPassword.php?fp_code='.$uniqidStr;
    $resetPassLink = 'http://localhost/gamewebsitetemplate/resetPassword.php?fp_code='.$uniqidStr;
    $_SESSION['link'] = $resetPassLink;
    $_SESSION['emailtorecover'] = $address;


    $arrContextOptions=array(
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );

    //$my_url = urlencode("https://guesswhothegame/gamewebsitetemplate/email_template.php?link=".$uniqidStr);

   $body = file_get_contents("http://localhost/gamewebsitetemplate/email_template.php?link=".$uniqidStr, false, stream_context_create($arrContextOptions));

    //$body = file_get_contents($my_url);

    $mail->IsSMTP(); // telling the class to use SMTP
    //$mail->Host       = "ssl://smtp.gmail.com"; // SMTP server
    $mail->SMTPDebug = 1;                     // enables SMTP debug information (for testing)
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPAuth = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port = 465;                   // set the SMTP port for the GMAIL server
    $mail->Username = "mioindirizzo@gmail.com";  // GMAIL username
    $mail->Password = "miapassword";            // GMAIL password

    $mail->SetFrom('from@gmail.com', 'Gmail');

    //$mail->AddReplyTo("user2@gmail.com', 'First Last");

    $mail->Subject = "Request Changing Password";

    //$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

    $mail->MsgHTML($body);

   
    $mail->AddAddress($address, "user");

    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if (!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        //echo "Message sent!";
        //header("location: emailcorrect.php");
        echo "<script language='javascript' type='text/javascript'>location.href='emailcorrect.php'</script>";

    }

}else{
    $error = "Insert a valid email address of an account of the game!";
    header("location: erroremail.php");
    //echo "<script> openPasswordRecovery(); </script>";
}

?>


come vedete questa genera un link che viene spedito al mio email template.php

la mia domanda è:

una volta che clicco sul link, e mi apre la mia pagina recovermail.php

come faccio a sapere a quale indirizzo email sto aggiornando la password per cambiarla??

perchè ho impostato una session ma credo che mi si svuoti e non riesco a cambiare la password
 

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
Però attento che il php del form non corrisponde al sendmail.php

Quale sarebbe il link da cliccare di cui parli ?
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
Lo genera nel sendemailwebsite.php...

Io ho due form nella main page.. nella prima è una form di login la seconda form è in un pannello che si apre con una funzione Javascript... ed è L html postato sopra...

Il link è generato dentro sendemailwebsite.php

Dentro la variabile $resetlink


Inviato dal mio iPhone utilizzando Toms Hardware Italia Forum
 

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
ho capito .
Stasera sono un po' stanco domani ti aiuto volentieri
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
ma se ho capito bene vuoi che il php visualizzi la mail di cui hai richiesto il recovery nel form ? Non puoi usare il solito $_POST['email-recovery']; ?

aaah vuoi mandarlo dal form html al sendmailwebsite.php e successivamente a sendmail.php ?

aggungi questo codice html al php intermedio :
HTML:
<input type="hidden"  name="email-ricovery"     value="<?php echo $_POST['email-ricovery']; ?>">

in pratica passi di "nascosto" il valore di email-ricovery del form iniziale alla pagina php che ti apre ..poi da qui con <?php echo $_POST['email-ricovery']; ?> ti esce la mail iniziale richiesta;
è questo che cercavi ?
 
Ultima modifica:

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
allora provo a spiegarmi meglio visto che sono in ufficio.
Io ho questa form dove inserisco la mail di recupero che si trova nella main page
ti mostro le immagini cosi è più facile da capire.

upload_2017-6-14_9-32-0.png

come vedi qui ho una form di login..
premendo su hai dimenticato la password, io apro un pannello modale:
cosi come da foto

upload_2017-6-14_9-32-46.png

questa è una seconda form presente in index.php.
questa form rilancia il sendemailwebsite.php
che usa un template genera un link e me lo manda via mail.
Questo link mi serve per accedere a recoverpassword.php,
solo che per ripristinare la password mi serve oltre al codice che mando io, la mail da aggiornare, altrimenti non funziona perchè nel db faccio
"UPDATE SET PASSWORD = NEWPASSWORD WHERE EMAIL = EMAIL"
solo che non so come far arrivare la mail che sta nel primo pannello...
cioè fino al sendEmail ce l'ho perchè mando la mail e mi arriva, ma da li poi me la perdo via.
 

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
ah ok metti anche recoverpassword.php
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
si aspetta vuoi il codice php o vedere la schermata html??
 

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
ma si dai solo il codice
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
faccio prima a far cosi

Codice:
<!DOCTYPE HTML>


<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


require_once 'main/main.php';

$db = new dbconnect;

$main = new main;


$main->sec_session_start();

$password = "";
$captcha = "";
$verify = "";
$message = "";
$email = "";
$secret = "";

if($_SERVER["REQUEST_METHOD"] == "POST") {


    if (isset($_POST['password'])) {
// check if the username has been set
        $password = $_POST['password'];

    }

    if (isset($_POST['verify-password'])) {
// check if the username has been set
        $verify = $_POST['verify-password'];

    }

    $email = $_SESSION['emailtorecover'];
    $captcha =  $_POST['fp_code'];
    $secret = '6Le1XyUUAAAAAB3FSnu_Y_UYMhJHdTlZ_WYf-fx3';

    $verify_response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&
    response='.$_POST['g-recaptcha-response']);
    $responsedata = json_decode($verify_response);

    if($responsedata->success) {

        if ($password === $verify) {
            $reset = $db->updatepassword($password, $captcha, $email);
        } else {
            $message = "The password are different, reinsert it!";
        }

    }

}


?>


<html>
<head>
    <meta charset="UTF-8">
    <title>GuessWho, l'indovina chi rivoluzionario</title>
    <link rel="stylesheet" href="css/style.css" type="text/css">
    <script src="scripts/js_scripts/script.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Fontdiner+Swanky" rel="stylesheet">
    <script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>


<div id="background">




    <div id="header">
        <div>
            <div>
                <a href="index.php" class="logo"><img src="immagini/guesswho.png" alt=""></a>
                <ul>
                    <li class="selected">
                        <a href="index.php" id="menu1">home</a>
                    </li>
                    <li>
                        <a href="media.php" id="menu2">media</a>
                    </li>
                    <li>
                        <a href="games.php" id="menu3">games</a>
                    </li>
                    <li>
                        <a href="about.php" id="menu4">about</a>
                    </li>
                    <li>
                        <a href="blog.php" id="menu5">blog</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <div id="body">
        <div>
            <div>
                <div class="featured">
                    <img src="immagini/featured-game.png" alt="">
                </div>
                <div class="section">
                    <div style="width:100%;">
                        <h3 style="font-family : foo;">Reset Password</h3>
                        <div id="form_login" style="width:100%;">

                            <form action="" method="POST" style="margin-left:30%;margin-right: 30%;">


                                    <?php echo $message; ?>

                                <label for="user" style="font-family: foo; font-size: 12px; color:#FFD700;">Insert the new password:</label><br><br>
                                <input type="password" name="password" placeholder="new password" required class="textField" style="width:300px; height:20px; font-family: 'Fontdiner Swanky', cursive;"  />
                                <br><br>
                                <label for="pass" style="font-family: foo; font-size: 12px;color:#FFD700;">Verify Password:</label><br><br>
                                <input type="password" class="textField" name="verify-password" placeholder="verify password" required  style="width:300px;height: 20px; font-family: 'Fontdiner Swanky', cursive;"><br><br>

                                <div class="g-recaptcha" data-sitekey="6Le1XyUUAAAAAAfKtsXW-Ki76LmbeaFqrgftyUVG" style="border: none;"></div>
                                <br><br>

                                <input type="image" value="Change" src="immagini/change.png" alt="Submit" style="width:40%;">

                                <input name="_token" value="" type="hidden">
                                <input type="hidden" name="fp_code" value="<?php echo $_REQUEST['fp_code']; ?>"/>

                            </form>

                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="footer">
        <div>
            <ul>
                <li id="facebook">
                    <a href="http://freewebsitetemplates.com/go/facebook/">facebook</a>
                </li>
                <li id="twitter">
                    <a href="http://freewebsitetemplates.com/go/twitter/">twitter</a>
                </li>
                <li id="googleplus">
                    <a href="http://freewebsitetemplates.com/go/googleplus/">googleplus</a>
                </li>
            </ul>
            <p>
                &copy; 2017 Mashroom Games. All Rights Reserved | Design by <a href="#">Mashroom Games</a>
            </p>
        </div>
    </div>



</div>



</body>
</html>

ho messo il codice di tutta la pagina....

considera che fp_code lo leggo dalla mail che mi arriva...
 

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
hai usato fp_code con type="hidden" , non riesci a fare lo stesso con la mail ?
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
eh ma quello lo passo dal template della mail, se tu controlli sopra, quando faccio questa chiamata nel sendemail

$body = file_get_contents("http://localhost/gamewebsitetemplate/email_template.php?link=".$uniqidStr, false, stream_context_create($arrContextOptions));

come vedi faccio un link= mio link
e dell'altra parte me lo becco con una get

ma la mail sarebbe in chiaro e leggibile per qualcuno

volevo evitare di mandarla cosi
 

elvan2

Utente Èlite
6,520
1,990
CPU
Intel i5 4590
Dissipatore
CM Hyper T4
Scheda Madre
H97 PLUS Asus
HDD
vari
RAM
HyperX (2X4GB) DDR3 1600MHz
GPU
Sapphire TOXIC R9 270X 2GB
PSU
Antec Neo Eco 520c
Case
Zalman z3
ho fatto una prova col mio sito e anche qua usa il get per reimpostare la pass peròsi vede in chiaro solo il nome utente e non la mail
ma anche se fosse la mail non è un grosso problema tanto la vede solo lui
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,440
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
quindi tu dici di mandare due params

la mail e l'fp_code in modo tale che io posso avere entrambi
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!

Discussioni Simili