faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

42 of 44 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes


I'm new to PHP, and would like to know if there is a code snippet for emailing a lost password to a customer. Thank you!

Feb 20th, 2008 22:54
dman, Cinley Rodick, Jeff Lyons, Mark Hermansen, http://www.ttnr.org

First, we must assume that you are currently storing the 
username/login, password and the email address in a mySQL table.  Once 
we know the username/login, we simply use that to locate the password 
and utilize the mail() function to send it.  
Your snippet would be something like this:
  $result = mysql_query ("SELECT password,email FROM yourtable 
                          WHERE username = '$username'");
  if ($myrow = mysql_fetch_array($result)) {
    $mailaddress = $myrow["email"];
    $subject     = "Important Message"; // don't say password in subject
    $message     = "Your password is: " . $myrow["password"] ;
    $header      = "Ancillary message or other stuff";
Hope this is helpful.