PHP Help

Soldato
Joined
26 Nov 2005
Posts
3,839
Location
Doon the Bay (Newcastle)
Hi thought i'd ask here to se if someone can point me in the right direction.

What i want to do is to send an email requested by the user containing data from a database.

Basically forgotten login details, so you send your email, and to your email you receive login details, username and password.

The database contains the persons email so that's how it would know who's details its checking for.

I've managed to create email send bit, and the email is sending i just need to know how to pull things from a database and send them via an email.

Cheers!

PS: I've got a Wrox php5, sql book which has been of decent help, but i can't find anything in it for a request like this, and i cannot find what i'm looking for on the net.

Thanks for looking.
 
Sounds easy when you know how, unfortunately i don't know how! :(

1st off how would i get the email given to match up with the DB, then how do i retrieve the values from the DB? (in code)
 
Can i ask the DB through php using SQL commands?

SELECT *
FROM 'Members'
WHERE 'EMAIL' = "myemail"

???
 
Last edited:
Sounds easy when you know how, unfortunately i don't know how! :(

1st off how would i get the email given to match up with the DB, then how do i retrieve the values from the DB? (in code)

PHP:
$email = $_POST['email'];
$sql = mysql_query("SELECT * FROM `database` WHERE `email` = '$email'");
$details = mysql_fetch_array($sql);

echo "Users details are:<br />"
echo $details['username'] . "<br />";
echo $details['password'] . "<br />";
echo $details['email'];

Thats only a guide for you.. :p As Im not entirely sure what you're wanting
 
Something like that for sure, still not working though, tried loads of combos but the email i send comes out blank.
 
Hi,

Firstly you'll need a form, just create a simple one containing something like:

PHP:
<form id="form" name="form" method="post" action="filename.php">

Try this:

PHP:
<?php
$host="localhost"; // Host name
$username=" insert shiz "; // Mysql username
$password=" insert shiz "; // Mysql password
$db_name=" insert shiz "; // Database name
$tbl_name=" insert shiz "; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db(" insert db ")or die("cannot select DB");

$email=$_POST['email'];

$tbl_name= tableNAME;
$sql="SELECT mypassword FROM $tbl_name WHERE email='$email'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
$rows=mysql_fetch_array($result);
$your_password=$rows['mypassword'];
$to=$email;
$subject="Will be whatever you want";
$header="From: [email protected]";
$messages.="Hello, seems you lost your password? Or some message to that effect\r\n";
$messages.="Your password is: $your_password \r\n";
$sentmail = mail($to,$subject,$messages,$header);
}

// if your email succesfully sent
if($sentmail){
 header("Location: emailsuccess.php");
}
else {
 header("Location: emailfail.php");
}

?>

Make sure you understand it, copying code without understanding always has an adverse effect ;)
 
I've got a separate file (which does work) which is my connection to the DB, i can get something in the email if i just wrote something, the problem being its not pulling the details from the DB.

I've even tried direct code in the php file (that i'm trying to get working) but its not working either.
 
Back
Top Bottom