Need help with Send Password form

I’m having trouble with the html that is sent to the user after they have filled in their details, it doesn’t display their password, everything else works fine but the password doesn’t show ($password).

<?php
require_once('../../Connections/localhost.php');
require('../../PHPMailer/PHPMailerAutoload.php'); 
if(isset($_POST) & !empty($_POST)){
	$username = mysql_real_escape_string($_POST['username'], $localhost);
	$sql = "SELECT * FROM kazbilli_kbg.kbg_affiliates WHERE kbg_affiliates.AffiliateID = '$username'";
	$res = mysql_query($sql, $localhost) or die(mysql_error());
	$count = mysql_num_rows($res);
	if($count == 1){
		$r = mysql_fetch_assoc($res);
		$password = $r['Password'];
		$to = $r['Email'];
$from = 'KBG Support <support@kazbillionairegroup.com>';
		$subject = "Your Recovered Password";
 
		$message = file_get_contents('email.html');
 $headers = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
 $headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion(5.6);
		if(mail($to,$subject,$message,$headers)){
			header('Location: password-sent.html');
		}else{
			echo "Failed to Recover your password, try again";
		}
 
	}else{
		echo "User name does not exist in database";
	}
}
 
 
?>


<!DOCTYPE html>

<!--[if IE 8 ]><html class="no-js oldie ie8" lang="en"> <![endif]-->

<!--[if IE 9 ]><html class="no-js oldie ie9" lang="en"> <![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->

<html class="no-js" lang="en"> 

<!--<![endif]-->

<head>
   <!-- ====== Basic Page Needs ====== -->
   <meta charset="utf-8">
   <title>KBG | Forgot Password?</title>
   <meta name="description" content="KBG is a forex signal service and education company. We aim to use forex as a medium to help you create financial freedom.">  
   <meta name="keywords" content="Kaz, KBG, Billionaire, Group, Kaz Billionaire Group, Wealth, Wealth Creation, Forex, Forex Service, Signals, Forex Signals, Forex Signal, Forex Education, Education, Profits, Expert, Advisor, Expert Advisor" />
   <!-- ====== Mobile Specs Meta ====== -->
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
   <!-- ====== CSS ====== -->
   <link rel="stylesheet" href="../../css/base.css">
   <link rel="stylesheet" href="../../css/vendor.css">  
   <link rel="stylesheet" href="../../css/main.css">
   <link rel="stylesheet" href="../../css/zerogrid.css">  
   <!-- ====== Java Scripts ====== -->
   <script src="../../js/modernizr.js"></script>
   <script src="../../js/pace.min.js"></script>
   <!-- ====== Favicon ====== -->
   <link rel="shortcut icon" href="../../favicon.png" type="image/x-icon">
   <link rel="icon" href="../../favicon.png" type="image/x-icon">
</head>

<body id="top">

   <!-- ====== Header Begin ====== -->

   <header> 
   	<div class="header-logo">
	      <a href="#">KBG</a>
	    </div> 
		<a id="header-menu-trigger" href="#0">
		 	<span class="header-menu-text" style="color: white">Menu</span>
		  	<span class="header-menu-icon"></span>
		</a> 
		<nav id="menu-nav-wrap">
			<a href="#0" class="close-button" title="close"><span>Close</span></a>	
	   	    <img alt="KBG" src="../../images/logo.png" style="height: 100px;width: 100px;" />  
			<ul class="nav-list">
				<li class="current"><a class="" href="../../index.html">Home</a></li>
				<li><a class="" href="../../about.html" title="">About</a></li>
				<li>
                    <a class="" >Services</a>
                <div>
               <ul>
                <li><a href="../../signal-service.html">Signal Service</a></li>
                <li><a href="../../account-management.html">Account Management</a></li>
                <li><a href="../../expert-advisor.html">Expert Advisor</a></li>
                <li><a href="../../forex-education.html">Forex Education</a></li>
               </ul>
             </div>
               </li>
                <li><a class="" href="../../affiliate-program.html" >Affiliate Program</a></li>
                <li><a class="" href="../../competition.html" >Competition</a></li>
                <li><a class="" href="../../login.php" >Sign In</a></li>
                <li><a class="" href="../../signup.html" >Sign Up</a></li>
				<li><a href="../../contact-us.html">Contact Us</a></li>						
			</ul>	
			<ul class="header-social-list">
	         <li>
	         	<a target="_blank" href="https://www.facebook.com/kazbillionairegroup"><i class="fa fa-facebook-square"></i></a>
	         </li>
	         <li>
	         	<a target="_blank" href="https://www.instagram.com/kazbillionairegroup"><i class="fa fa-instagram"></i></a>
	         </li>
	      </ul>		
		</nav>  <!-- end #menu-nav-wrap -->
	</header>     
    
   <!-- ====== Header End ====== -->     
    
   <!-- ====== Login Begin ====== -->

    <section id="services">
        <div class="overlay"></div>
        <div class="zerogrid">
            <div class="row">
                <!--Start Box-->
                <div class="col-1-3 offset-1-3">
                    <div class="wrap-col">
                        <div class="row">
                            <div class="animate-this">
                                <h1 style="color: white">Forgot Password?</h1>
                                <p class="lead" style="color: white">Fill in your username below and we will send you your password.</p>
                                 <?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
                                 <?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>      
                                <form method="post">
                                    <div class="form-field">
                                        <input name="username" style="color: white" class="full-width" type="text" id="username" placeholder="Affiliate ID" value="" minlength="8" required>
                                    </div>
                                    <div class="form-field">
                                        <input type="submit" class="submitform full-width" style="background-color: white; color: black" value="Send" name="forgotpassword">
                                    </div>
                                    <a href="login.html" style="color: white">Go Back</a>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
   
   <!-- ====== Login End ====== -->

   <!-- ====== Footer Begin ====== -->

    <footer>
        <div class="footer-main">
            <div class="row">
                <div class="col-eight tab-full footer-about">
                    <h4 class="h05">Kaz Billionaire Group</h4>
                    <div class="col-1-4">
                        <ul class="list-links">
                            <li><a href="../../index.html">Home</a></li>
                            <li><a href="../../about.html">About</a></li>
                            <li><a href="../../competition.html">Competition</a></li>
                        </ul>
                    </div>
                    <div class="col-1-4">
                        <ul class="list-links">
                            <li><a href="../../login.html">Sign In</a></li>
                            <li><a href="../../signup.html">Sign Up</a></li>
                            <li><a href="../../contact-us.html">Contact Us</a></li>
                        </ul>
                    </div>
                    <div class="col-2-4">
                        <ul class="list-links">
                            <li><a href="../../affiliate-program.html">Affiliate Program</a></li>
                            <li><a href="../../risk-disclosure.html">Risk Disclosure</a></li>
                            <li><a href="../../cookie-policy.html">Cookie Policy</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col-four tab-full footer-subscribe end">
                    <h4 class="h05">Get Notified.</h4>
                    <div class="subscribe-form">
                        <form id="mc-form" class="group" novalidate>
                            <input type="email" value="" name="dEmail" class="email" id="mc-email" placeholder="Email" required>
                            <button><i class="icon-mail"></i></button>
                            <label for="mc-email" class="subscribe-message"></label>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="row">
                <div class="col-full">
                    <div class="copyright">
                        <span>© Copyright KBG 2017.</span>
                    </div>
                </div>
            </div>
        </div>
        <div id="go-top">
            <a class="smoothscroll" title="Back to Top" href="#top">
                <i class="fa fa-long-arrow-up" aria-hidden="true"></i>
            </a>
        </div>
    </footer>
       
   <!-- ====== Footer End ====== -->

   <div id="preloader"> 
    	<div id="loader"></div>
   </div> 

    <!-- ====== Java Scripts ====== --> 

   <script src="../../js/jquery-2.1.3.min.js"></script>
   <script src="../../js/plugins.js"></script>
   <script src="../../js/main.js"></script>
    <script src="../../js/cookiechoices.js"></script>
    <script>
        cookieChoices.showCookieBar({
        linkHref: '../../cookie-policy.html',
        language: 'en'
        });
    </script>

</body>
</html>

below is the file email.html

<html>
<head></head><body>
<div style="font-family:HelveticaNeue-Light,Arial,sans-serif;background-color: black">
	<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0" style="background: url(https://www.kazbillionairegroup.com/images/services-bg.jpg) no-repeat 0 0; background-size: auto cover; min-height: 100%">
    <tbody>
        <tr>
        	<td>
                <table align="center" width="750px" border="0" cellspacing="0" cellpadding="0" style="width:750px!important; background: transparent">
                <tbody>
                	<tr>
                    	<td>
                			<table width="690" align="center" border="0" cellspacing="0" cellpadding="0" bgcolor="#eeeeee">
                            <tbody>
                            	<tr>
                                    <td colspan="3" height="80" align="center" border="0" cellspacing="0" cellpadding="0" bgcolor="black" style="padding:0;margin:0;font-size:0;line-height:0">
                                        <table width="690" align="center" border="0" cellspacing="0" cellpadding="0">
                                        <tbody>
                                        	<tr>
                                            	<td width="30"></td>
                                                <td align="center" valign="middle" style="padding:0;margin:0;font-size:0;line-height:0"><a href="https://www.kazbillionairegroup.com/" target="_blank"><img style="max-height: 150px; max-width: 150px" src="https://www.kazbillionairegroup.com/images/logo.png" alt="KBG" ></a></td>
                                                <td width="30"></td>
                                            </tr>
                                       	</tbody>
                                        </table>
                                  	</td>
                    			</tr>
                                <tr>
                                    <td colspan="3" align="center">
                                        <table width="630" align="center" border="0" cellspacing="0" cellpadding="0">
                                        <tbody>
                                        	<tr>
                                            	<td colspan="3" height="60"></td></tr><tr><td width="25"></td>
                                                <td align="center">
                                                    <h1 style="font-family:HelveticaNeue-Light,arial,sans-serif;font-size:48px;color:black;line-height:48px;font-weight:bold;margin:0;padding:0">Forgot Your Password?</h1>
                                                </td>
                                                <td width="25"></td>
                                            </tr>
                                            <tr>
                                            	<td colspan="3" height="40"></td></tr><tr><td colspan="5" align="center">
                                                    <p style="color:black;font-size:16px;line-height:24px;font-weight:lighter;padding:0;margin:0">We've decrypted your password from our database for you.</p>
                                                    <p style="color:black;font-size:16px;line-height:24px;font-weight:lighter;padding:0;margin:0">Please reset it the next time you login.</p><br>
                                                    <p style="color:black;font-size:16px;line-height:22px;font-weight:lighter;padding:0;margin:0">Your password is:</p>
                                                </td>
                                            </tr>
                                            <tr>
                                            <td colspan="4">
                                                <div style="width:100%;text-align:center;margin:30px 0">
                                                    <table align="center" cellpadding="0" cellspacing="0" style="font-family:HelveticaNeue-Light,Arial,sans-serif;margin:0 auto;padding:0">
                                                    <tbody>
                                                    	<tr>
                                                            <td align="center" style="margin:0;text-align:center"><a style="font-size:21px;line-height:22px;text-decoration:none;color:black;font-weight:bold;border-radius:2px;background-color:white;padding:14px 40px;display:block;letter-spacing:1.2px"> $password </a></td>
                                                      	</tr>
                                                   	</tbody>
                                                    </table>
                                               	</div>
                                           	</td>
                                       	</tr>
                                        <tr><td colspan="3" height="30"></td></tr>
                                 	</tbody>
                                    </table>
                             	</td>
                   			</tr>
                          	</tbody>
                            </table>
                  			<table align="center" width="690px" border="0" cellspacing="0" cellpadding="0" style="width:690px!important; background: black">
                            <tbody>
                            	<tr>
                                	<td>
                                        <table width="630" align="center" border="0" cellspacing="0" cellpadding="0" bgcolor="black">
                                        <tbody>
                                        	<tr><td colspan="2" height="30"></td></tr>
                                            <tr>
                                            	<td width="630" align="center" valign="top" >
                                                	<div style="color:white;font-size:12px;line-height:12px;padding:0;margin:0">&copy; KBG 2017. All rights reserved.</div>
                                                	<div style="line-height:24px;padding:0;margin:0">&nbsp;</div>
                                        		</td>
                                            </tr>
                                            <tr><td colspan="2" height="5"></td></tr>
                                           
                                      	</tbody>
                                        </table>
                                   	</td>
                  				</tr>
                          	</tbody>
                            </table>
                  		</td>
                	</tr>
              	</tbody>
                </table>
            </td>
		</tr>
 	</tbody>
    </table>
</div>
</body>
</html>

it is the code that is sent to the user after the filled in their details but it doesn’t display the users password.
Someone please help

In reality you should not be storing unhashed passwords in your database at all, it’s a security no no. Passwords should be hashed, and if forgotten, ask the user to create a new one.
Likewise you should not still be using the obsolete mysql API, that’s another security and compatibility flaw.
It may not seem very helpful, but you need to update your system to modern standards if you take security at all seriously.

But until I update it how do I get the password to show when sent to their email?

What do you see in place of the password?

$message = file_get_contents('email.html');
<td align="center" style="margin:0;text-align:center"><a style="font-size:21px;line-height:22px;text-decoration:none;color:black;font-weight:bold;border-radius:2px;background-color:white;padding:14px 40px;display:block;letter-spacing:1.2px"> $password </a></td>

I’m not certain, as I have not tried it, but I don’t think file_get_contents() will parse variables placed in an html file like you are expecting.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.