/    Sign up×
Community /Pin to ProfileBookmark

snedmail from form

Hi, i have a form where the user enters in their email address, what i want is to look in my database for their email, retreive their password and send it in an email to their address.

any siggestions?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ephmynusApr 17.2005 — [code=php]
$emailaddress = $_POST['emailaddress'];
$result = mysql_query("SELECT password, email WHERE email='$emailaddress'");
$subject = "Your Password";
while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
$mailcontent = "Your password is ".$row{'password'}.".";
}

mail ($emailaddress,$subject,$mailcontent,"From: webmasterATyourdomain.com");
[/code]
Copy linkTweet thisAlerts:
@gaston9x19Apr 17.2005 — Your SQL query should look something like this:

"SELECT password FROM yoursite_users WHERE email = '$_REQUEST[email]' ;"

If you want to use PEAR:?B classes to access the database...

[code=php]
<?php

// setup database connection and objects

$host="localhost";
$user="username";
$pass="password";
$database="database_name";

$db_engine = 'mysql';

//----- available db engines -----//
// mysql -> MySQL
// pgsql -> PostgreSQL
// ibase -> InterBase
// msql -> Mini SQL
// mssql -> Microsoft SQL Server
// oci8 -> Oracle 7/8/8i
// odbc -> ODBC (Open Database Connectivity)
// sybase -> SyBase
// ifx -> Informix
// fbsql -> FrontBase

require_once 'DB.php'; //require the PEAR::DB classes.

$datasource = $db_engine.'://'.$user.':'.$pass.'@'.$host.'/'.$database;

$db_object = DB::connect($datasource, TRUE);
/* assign database object in $db_object, if the connection fails $db_object will contain
the error message. */

if(DB::isError($db_object)) {
die($db_object->getMessage()); // If $db_object contains an error print out the
} // error and exit.

$db_object->setFetchMode(DB_FETCHMODE_ASSOC);



// begin actual query process

$sql="SELECT password FROM yoursite_users WHERE email = '$_REQUEST[email]';";
$passObject=$db_object->query($sql);
if(DB::isError($passObject)){
print "Error: table 'yoursite_users' does not exist or bad SQL query!<br/>nn";
echo $sql;
}else if($passObject->numRows()==0){
print "No user with that email address exists.nn";
}else{
$passArray=$passObject->fetchRow();
$to=$_REQUEST['email'];
$subject="Lost password retrieval.";
$contents="Your password is ".$passArray['password'];
$headers = 'From: lost_password@' . $_SERVER['SERVER_NAME'] . "rn" .
'X-Mailer: PHP/' . phpversion();

// lines longer than 70 chars can mess up the mail() function
$contents=wordwrap($contents, 70);

$emailSent=mail($to, $subject, $contents, $headers);
if($emailSent){
print "Password sent to your email address!nn";
}else{
print "Error: email could not be sent.nn";
}//end if email sent
}//end if error or numrows

$db_object->disconnect();

?>
[/code]


This script takes a single form element named "email" and looks for the password for the user with that email address. If the table "yoursite_users" doesn't exist or the SQL query gets messed up somehow, it points this out and does nothing else. If there is no user with that email address, there will be 0 rows in the $passObject array, and it will print out an appropriate message and do nothing more. If neither of these two conditions occur, it fires off an email to the address provided containing the password.

Hope this helps ?
Copy linkTweet thisAlerts:
@SheldonauthorApr 17.2005 — oh i forgot to mention that my database file is a flat file, seperated as such;

peter<del>202cb962ac59075b964b07152d234b70<del>0<del>[email protected]<del>www.slweb.co.nz<del>14.05.2005<del>Auckland<del>17.04.2005 09:37:49
Copy linkTweet thisAlerts:
@gaston9x19Apr 17.2005 — Have fun with substr() and strlen() lol... Sorry, I hate working with flat database files :-P Never have very much. You might try using explode() to separate everything into an array if your separators are identical, make it a little easier to work with. I dunno.
×

Success!

Help @Sheldon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...