Jump to content

[SOLVED] Generate email


mjgdunne

Recommended Posts

Hi, i have this code for forgot password for users it sends an email to the user with their username email address and password if the username and email address combination are correct, i have it set up and i am getting the emails throuogh but none of the details are appearing, its probably something basic but iv been looking at it for hours and i no im missing code.

Any help would be great as im new to php.Thanks.

 

<?php

session_start();

ini_set( 'display_errors', '1' );
error_reporting ( 2047 );

$fromemail = "postmaster@localhost";
$scripturl = "http://localhost/xampp/mailsend.php";


$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "root", "root")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form
$myusername=$_POST['myusername'];
$myemail=$_POST['myemail'];

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and email='$myemail'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $myemail, table row must be 1 row

if($count==1){

$sql="SELECT * FROM $tbl_name WHERE email = '$myemail'";
$resultID=mysql_query($sql);

$row = mysql_fetch_array($resultID);
$password = $row[0];

// End of query commands
// Send Password to email


$subject = 'Your Password';
$message = 'Go to ' . $scripturl . '?action=change&email='. $myemail .'&pass='. $password .' to change your password.';
$headers = 'From: postmaster@localhost' . "\r\n" .
    'Reply-To: postmaster@localhost' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($myemail, $subject, $message, $headers);

header("location:email_sent.php");

}
else {
header("location:login_failure.php");
echo "We are sorry, your Email and username do not appear to be in our database";
}
exit();
?>

Link to comment
Share on other sites

I dont know what details arent appearing. Do u get the email but dont get the reset link? Anyway im seeing some stuff there:

 

U have made the same query 2 times, so to shorten a bit the execution time and probably write them more organized:

 

<?php
$result = mysql_query("SELECT password, email FROM $tbl_name WHERE username='$myusername' and email='$myemail'");
if(mysql_num_rows($result) == 1){
   $values = mysql_fetch_array($result);
   $password = $values['password'];
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.