SauloA Posted May 24, 2007 Share Posted May 24, 2007 I am trying to adjust the code below to send a user's username and password by inputting an e-mail in the text box and clicking submit. The code below does work. The code below resets a user's password and sends the new password to their email. I don't want the password to reset and get sent, I just want the existing password to be sent. Also, the email doesn't include the username cuz i don't know how to include it in the email. The name of the table that holds the user's informatin in my database is "user_tbl". The username, password, and email fields in "user_tbl" are named respectively "user_sname", "user_pass", and "user_email". Please use these names when changing the code. I've tried to change the code with my minimal knowledge of PHP several times but the results were a failure. I've been trying to fix this issue for along time and have posted this topic a couple times on PHPfreaks. Hopefully the problem will end here. Thanks for the help. <?php session_start(); // Start Session session_register("session"); // This is displayed if all the fields are not filled in $empty_fields_message = "<p>PLEASE GO BACK AND COMPLETE ALL THE FIELDS ON THE FORM.</p>CLICK <a class=\"two\" href=\"javascript:history.go(-1)\">HERE</a> TO GO BACK."; // Convert to simple variables $user_email = $_POST['user_email']; if (!isset($_POST['user_email'])) { ?> <h2>RECOVER A FORGOTTEN PASSWORD</h2><hr> <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <p><label for="user_email">E-MAIL:</label> <input type="text" title="Please enter your email address" name="user_email" size="30"/> <input type="submit" value="Submit" class="submit-button"/></p> </form> <?php } elseif (empty($user_email)) { echo $empty_fields_message; } else { $user_email=mysql_real_escape_string($user_email); $status = "OK"; $msg=""; //error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); if (!stristr($user_email,"@") OR !stristr($user_email,".")) { $msg="YOUR E-MAIL ADDRESS IS NOT CORRECT.<BR>"; $status= "NOTOK";} mysql_select_db($database_connBlog, $connBlog); echo "<br><br>"; if($status=="OK"){ $query="SELECT user_email,user_sname FROM user_tbl WHERE user_tbl.user_email = '$user_email'"; $st=mysql_query($query, $connBlog) or die(mysql_error()); $recs=mysql_num_rows($st); $row=mysql_fetch_object($st); $em=$row->user_email;// email is stored to a variable if ($recs == 0) { echo "<center><font face='Verdana' size='2' color=red><b>No Password</b><br> Sorry Your address is not in our database. You can signup and login to use our site. <BR><BR><a href='newuser.php'>Register</a> </center>"; exit;} function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); $sql = mysql_query("UPDATE user_tbl SET user_pass='$db_password' WHERE user_email='$user_email'"); $subject = "Your login at www.example.com"; $message = "Greetings, we have reset your password. New Password: $random_password http://example.com Once logged in you can change your password Thanks! Site admin This is an automated response, please do not reply!"; mail($user_email, $subject, $message, "From: example.com Webmaster<sauloa@example.com>\n X-Mailer: PHP/" . phpversion()); echo "Your password has been sent! Please check your email!<br />"; echo "<br><br>Click <a href='http://www.example.com'>here</a> to login"; } else {echo "<center><font face='Verdana' size='2' color=red >$msg <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52767-solved-sending-login-info-to-user-via-e-mail-help/ Share on other sites More sharing options...
redarrow Posted May 24, 2007 Share Posted May 24, 2007 here mine might help ok. <?php session_start(); $db=mysql_connect("localhost","username","password"); mysql_select_db("database",$db); echo" <html> <head> <title>Dj Phc</title> <body bgcolor='#ff333' vlink='blue' link='blue' alink='blue'>"; include("header.php"); echo"<br><br><h1><div align='center'>Forgot password</h1></div><br>"; $query="select mail,password from blog_register where mail='$mail'"; $result=mysql_query($query); while($rec=mysql_fetch_assoc($result)){ $mail=$_SESSION['mail']=$rec['mail']; } if(mysql_num_rows($result)==1){ if($_GET['cmd']=="update"){ $query2="update `blog_register` set `password`='$password' where `mail` = '$mail' "; $result=mysql_query($query2)or die(mysql_error()); $to = $mail; $subject = 'new password(www.djphc.com)'; $message = '<html><body><h2>please keep this new password in a safe place</h2><br><br>Your new password is: '.$password.'</body></html>'; $headers = "From: administator@email.com\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; mail($to, $subject, $message, $headers); echo " <div align='center'><font color='yellow'>Thank you password changed!<br> We have sent a copy to your email address!<div></font><br><br><a href='login.php'>please login</a>"; exit; } if($_GET['cmd']=="pro"){ echo"<div align='center'><form action='forgot_password.php?cmd=update ' method='POST'> <font color='yellow'>Please provide a new password</font><br><br> <input type='text' name='password' maxlength='30'> <br> <br> <input type='submit' name='submit' value='New Password'> </form></div>"; exit; } } ?> <div align='center'> <form action="forgot_password.php?cmd=pro" method="POST"> <font color='yellow'>Please provide registration email address</font><br><br> <input type="text" name="mail" maxlength="30"> <br> <br> <input type="submit" name="protect" value="Confirm email address"> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/52767-solved-sending-login-info-to-user-via-e-mail-help/#findComment-260530 Share on other sites More sharing options...
SauloA Posted May 24, 2007 Author Share Posted May 24, 2007 redarrow I can't change your code to work with my specifications. I modified it a little and when I push the submit button nothing happens. Can someone tell me what the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/52767-solved-sending-login-info-to-user-via-e-mail-help/#findComment-260950 Share on other sites More sharing options...
SauloA Posted May 24, 2007 Author Share Posted May 24, 2007 I found the solution to my problem. I found my solution here http://www.phpeasystep.com/workshopview.php?id=21. Thanks anyways. Hopefully I have helped those who have the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/52767-solved-sending-login-info-to-user-via-e-mail-help/#findComment-261092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.