PHP Email Problem

Hi

I have created a php forgotten password page but when I receive the forgotten password email, I only get the email address in the email and not the username and password, its not collecting the username and password data for some reason

The php coding is below in the forgottenpassword.php

[php]<?php
if($go == “1”) {
$connect = mysql_connect(“host”,“username”,“password”);
if (!$connect) { die(“MySQL could not connect!”); }
$DB = mysql_select_db(‘databasename’);
if(!$DB) { die(“My SQL could not select Database!”); } }
$Username = $_POST[‘username’];
$Email = $_POST[‘email’];
$Email1 = “@”;
$Email_Check = strpos($Email,$Email1);
$Password = $_POST[‘password’];
$message_field = $_POST[‘username, password’];
$message = “$Email, $Username, $Password, $message_field”;
?>

<?php //These are the variables for the email $sendto = $_POST['email']; // this is the email address collected from the form $ccto = "[email protected]"; //you can cc it to yourself $subject = "Your Registration Details"; // Subject $message = "Email Address: " . $Email . "\n\n" . "Username: " . $Username . "\n\n" . "Password: " . $Password . "\n\n" . "$message_field"; $header = "From: [email protected]\r\n"; $header .= "Reply-to: [email protected]\r\n"; // This is the function to send the email mail($sendto, $subject, $message, $header, $message_field); echo "Your password has been sent to ". $Email ."."; ?>[/php]

Below is what the email comes out like

Email Address: [email protected]

Username:

Password:

my html form is below

<form action="forgotpassword.php" method="post"> E-mail: <input type="text" name="email" size="24" border="0"> <br> <input type="hidden" name="username" border="0"> <input type="hidden" name="password" border="0"> <input type="hidden" name="go" value="1" border="0"> <input type="submit" name="submitButtonName" value="Submit" border="0"> </form>

Please help, been stuck on this for a while now

Kind regards

Ian

you made your code in one line so the comment out line commented out just about the whole script

make your code down the page so it is legible to us so we know what code you have and dont have to work

first off you are trying to get a password from that database you need a query to ask the database to give you that password

[php]
$sql = “SELECT * FROM members WHERE user_email = ‘$Email’”;
$result = mysql_query($sql)or die('Could not find member: ’ . mysql_error());
$row = mysql_fetch_array ($result);
$Username = $row[‘username’];
$Password = $row[‘password’]
[/php]

something like that

Would just like to add you are trying to retrieve the password there is no point having a hidden field in your form with password as this is going to be empty only uername or email should be used to get the forgottem password.

$Password will hold your password to send in the email.
[php]$Password = $row[‘password’];[/php]

Just a Note: You shouldn’t be storing the actual password. The password you store should be stored as a MD5 SHA1 etc of the password. Then for a forgotten password you can email them (to the email address you have in your database) a temporary password reset link.

yes on what both noodles and radix said my example was an example but if you were going to make a reset you need to have it so it will get your password that you input somehow md5 it or how you want it

You need to do a reset the password which means you will have to make a new password random generator to send to people.

So they input there email so you can send them the new password with a activation as you do not want to let others in.

You would need a way of making the password and a random activation they can send back so the script knows its them,as you do not want people changing other peoples passwords, then send the email with the new password in it.

So its not quite as simple unless you have plain text passwords then.

Sponsor our Newsletter | Privacy Policy | Terms of Service