dudejma Posted August 1, 2011 Share Posted August 1, 2011 Why's this code not working? It doesn't give any errors, it just goes to the forgotPass1.php and doesn't do anything. <?php require 'include/sql.php'; if (isset($_POST['submit'])) { $pilotid = $_POST['pilotid']; $random = md5(uniqid(rand())); $sql = "SELECT * FROM users WHERE pilotID='$pilotid'"; $result = mysql_query($sql) or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { $to = $row['email']; $message = "This email was sent because someone recently requested for a password reset for your account. If this was not you, please disregard this email. If it was you, click <a href=\"forgotPass2.php?" . $random . "\">here</a> to reset your password."; $subject = "Password Reset"; $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; $headers .= "From: Virtual American Airlines <applications@virtualamerican.org>\r\n"; $headers .= "Reply-To: Virtual American Airlines <applications@virtualamerican.org>\r\n"; $headers .= "Return-Path: Virtual American Airlines <applications@virtualamerican.org>\r\n"; $headers .= "X-Mailer: PHP". phpversion() ."\r\n"; $sql2 = "INSERT INTO temp_pass (pilotID, random) VALUES ('$pilotid', '$random')"; $result2 = mysql_query($sql2) or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error()); mail($to,$subject,$message,$headers) or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error()); $errors = "We have sent you your password. Please check your email."; header("Location: login.php"); } } ?> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/ Share on other sites More sharing options...
JohnOP Posted August 1, 2011 Share Posted August 1, 2011 Only problem i can see it that mail() is missing the line terminator. Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/#findComment-1250004 Share on other sites More sharing options...
AyKay47 Posted August 1, 2011 Share Posted August 1, 2011 mail($to,$subject,$message,$headers) or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error()); the mail() function would not report a mysql_error...you can do something like this instead.. if(!mail($to,$subject,$message,$headers)){ trigger_error("An error has occurred in the mailing process",E_USER_ERROR); } also, I do not see a forgotPass1.php in the code you provided Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/#findComment-1250006 Share on other sites More sharing options...
dudejma Posted August 1, 2011 Author Share Posted August 1, 2011 This is the code to forgotPass1.php. I tried to use PHP_SELF but it didn't do anything that time either so I moved it to it's own page thinking that it might work then, but it still didn't. Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/#findComment-1250008 Share on other sites More sharing options...
AyKay47 Posted August 1, 2011 Share Posted August 1, 2011 if you change to the code that I have provided, what errors do you receive in your error.log? If this is a mail() error, something will be sent to the error.log about it.. Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/#findComment-1250010 Share on other sites More sharing options...
dudejma Posted August 1, 2011 Author Share Posted August 1, 2011 It doesn't give an error. The last error in the log is one from forty-five minutes ago. Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/#findComment-1250015 Share on other sites More sharing options...
AyKay47 Posted August 1, 2011 Share Posted August 1, 2011 if you do not receive an error then you should be receiving the email, check you junk/spam folder as well Quote Link to comment https://forums.phpfreaks.com/topic/243424-code-not-working/#findComment-1250017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.