Send the forgotten password to the mail address

Discussion in 'PHP' started by coder 525, Jul 10, 2008.

  1. #1
    I am trying to send the forgotten password to the mail address captured.
    The code is as follows. I am getting the message Your password has been sent to the mail id. Also correct password is selected from the database. But I am not receiving the message. I hava a contact us form in my site. It is working fine. I can not fix this...
    Any help...

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

    // value sent from form
    $email_to=$_POST['email'];

    // table name
    $tbl_name="tb_signup";

    // retrieve password from table where e-mail = $email_to
    $sql="SELECT password FROM $tbl_name WHERE email='$email_to'";
    $result=mysql_query($sql);

    // if found this e-mail address, row must be 1 row
    // keep value in variable name "$count"
    $count=mysql_num_rows($result);

    // compare if $count =1 row
    if($count==1){

    $rows=mysql_fetch_array($result);

    // keep password in $your_password
    $your_password=$rows['password'];
    echo $your_password;

    // ---------------- SEND MAIL FORM ----------------

    // send e-mail to ...
    $to=$email_to;

    // Your subject
    $subject="Your password here";

    // From
    $visitormail="reachme@worth2read.org";
    $from = "From: $visitormail\r\n";
    echo $from;

    // Your message
    $messages= "Your password for login to our website \r\n";
    $messages.="Your password is $your_password \r\n";
    $messages.="more message... \r\n";

    // send email
    $sentmail = mail($to,$subject,$messages,$from);
    echo $sentmail;
    }

    // else if $count not equal 1
    else {
    echo "Not found your email in our database";
    }

    // if your email succesfully sent
    if($sentmail){
    echo "Your Password Has Been Sent To Your Email Address.";
    }
    else {
    echo "Cannot send password to your e-mail address";
    }

    ?>
     
    coder 525, Jul 10, 2008 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    I hope it helps.

    regards
     
    Vooler, Jul 10, 2008 IP
  3. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Still not getting the email... All the echo statements are working correctly
     
    coder 525, Jul 10, 2008 IP
  4. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #4
    check the junk mail or spam folder of "reachme@worth2read.org".

    Are you sure function mail() is not producin ga warning or error.
    And does script show final message "Your Password Has Been Sent To Your Email Address." ?

    regards
     
    Vooler, Jul 10, 2008 IP
  5. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    is the from address. I am sending mail to the mail id in the database/ or the mail id user enters. the circumstance is the visitor forgot password and I am sending it to the visitor's id. Since I put the echo statements in the code, I am getting password correctly. Also the our Password Has Been Sent To Your Email Address' message is coming. The value of sentmail is shown as 1 also...I checked the spam folders. It has not come...
     
    coder 525, Jul 10, 2008 IP
  6. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Could you use [^php^]CODE HERE[/^PHP^] *remove ^*
    It's really hard to read the code without a wrapper =/

    At the top of everyone *around in <?php* put error_reporting('E_ALL'); also, when grabbing the sql row, echo $to_email to see if its pasting.
     
    Mozzart, Jul 10, 2008 IP
  7. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    coder 525, Jul 10, 2008 IP
  8. gezzle

    gezzle Peon

    Messages:
    108
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    the mail function by default uses the mail transfer agent sendmail to send all mails. In some linux box I think sendmail are not configured properly. Why don't you use phpmailer, simple and clean to use, object oriented. I'll highly recommend it :
    http://phpmailer.codeworxtech.com/
     
    gezzle, Jul 10, 2008 IP
  9. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #9
    I tried error_reporting('E_ALL');
    No error came...

    ... That turns off error reporting!

    The line you want is:

    error_reporting(E_ALL);
     
    Danltn, Jul 10, 2008 IP
  10. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ahh d'oh forgot they are without quotes, ah well

    Maybe gezzle is right (about sendmail *or postfix or qmail* being misconfigured, or there is something in the source we haven't seen, as you are pasting just the part of what it should do, but not the forms used and how it manages $_POST. Heck it might even be a little <form> problem perhaps

    Also you might want to rethink the way you are storing passwords... just storing them plain raw.. well just my 2 cents on that part.
     
    Mozzart, Jul 10, 2008 IP
  11. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I appreciate ur comments.
    I tried everything. All the echo stmts r working...Getting the message mail is send. But I am not getting mail.
    Now I noticed that among server information it is written as
    Path to send mail : /usr/sbin/sendmail
    Does it have something to do with the code...
     
    coder 525, Jul 10, 2008 IP
  12. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hi
    The following simple code also is not working...

    <?php
    error_reporting(E_ALL);
    $to="admin@yahoo.com.sg";
    $subject="message";
    $messages= "Your password is \r\n";
    $mailheader = 'From: "admin" <reachme@worth2read.org>' . "\r\n" .
    'Reply-To: ' . "\r\n" .
    'x-mailer: php/' . phpversion() . "\r\n";
    if( mail( $to,$subject,$messages,$mailheader))
    {
    echo "We've sent the mail.\n";
    }
    else {
    echo "Could not send mail. Please try again later\n";
    }
    ?>
     
    coder 525, Jul 10, 2008 IP
  13. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I think it is the problem with email configuration. I can send mail to the mail ids in my domain, ie I can send mail to . To other mail ids(Yahoo, Gmail etc) I can't send...
    Any ideas..
     
    coder 525, Jul 10, 2008 IP
  14. davegwan

    davegwan Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #14
    Do you use shared hosting?
    Sometimes email from shared hosting just got deleted/blocked without notices (not even put in the SPAM box).

    My suggestion:
    If the mail you send using your hosting webmail from reach Yahoo, Gmail, etc.
    Find out what is your email SMTP settings, then try to use email SMTP library (like Swift Mailer http://swiftmailer.org/ to send the email trough your SMTP directly, bypassing the sendmail).
     
    davegwan, Jul 10, 2008 IP