Linneus 0 Report post Posted March 22, 2005 I'm trying to use the mail() function in a script. But it doesnt work. It keeps returning false.It's a premade scriptThe code is: function SendPassword($userName){global $db,$db_tables;//config.php // set password for username to a random value // return the new password or false on failure $new_password = mt_rand(); $qry = "UPDATE $db_tables[Users] SET password=password('$new_password') WHERE user_name='$userName'"; $db->db_query($qry); // send notification email $from = "From: $from_email\r\n"; $msg = "You or someone pretending to be you has requested that your" . "password be changed for your bookmark account hosted at http://$domain/$subdir\r\n\r\n" . "Your account password has been changed to $new_password\r\n" . "Please change it next time you log in.\r\n"; if (!mail("$email", "Login information", $msg, $from)) { echo "ERROR : Unable to send notification email. Please contact the <a href=\"mailto:$admin@$domain\">Administrator</a>"; }} Share this post Link to post Share on other sites
rkage 0 Report post Posted March 22, 2005 Just a few questions to help me see whats wrong;Are you sure your host allows the mail function (if not using Xisto)?When you say return false, do you mean it shows the "Contact admin" self made error or it displays a PHP error?Also try doing just this; mail("$email", "Login information", $msg, $from) See if that returns a PHP error when you try to send it. I'm not sure which part of the mail script isn't working but why is there quotes round the email but not the msg and from? I'll try helping you once you reply, it's hard for me to test scripts that rely on databases since if the database isn't functioning a code properly, it will return an error and hence the rest will not work and return an error. Share this post Link to post Share on other sites
Linneus 0 Report post Posted March 22, 2005 I have changed to code to: function SendPassword($userName){global $db,$db_tables;//config.php // set password for username to a random value // return the new password or false on failure $new_password = mt_rand(); $qry = "UPDATE $db_tables[Users] SET password=password('$new_password') WHERE user_name='$userName'"; $db->db_query($qry); // send notification email $from = "From: $from_email\r\n"; $msg = "You or someone pretending to be you has requested that your" . "password be changed for your bookmark account hosted at http://$domain/$subdir\r\n\r\n" . "Your account password has been changed to $new_password\r\n" . "Please change it next time you log in.\r\n"; if (!mail($userName, "Login information", $msg, $from)) { echo "ERROR : Unable to send notification email. Please contact the <a href=\"mailto:$admin@$domain\">Administrator</a>"; }} Now it doesnt show it self made error message. But I don't get any mail from it. Anyway all usernames are email-addresses. I've tried to change if (!mail($userName, "Login information", $msg, $from)) toif (!mail("linneuscool@hotmail.com", "Login information", $msg, $from)) linneuscool@hotmail.com is my email-address. But it doesnt even work then. Share this post Link to post Share on other sites
rkage 0 Report post Posted March 22, 2005 Did you try the mail on it's own without any IF statements. I know there are some functions that won't work when nested in an if statement. I really can't see what is wrong. If this is a premade script it should be working... Just to verify, and it may be stating the obvious, but you are sure your host allows the mail command and that you are checking your inbox, including any junkmail filters? Share this post Link to post Share on other sites
Linneus 0 Report post Posted March 23, 2005 It works now. It was in spam-box because I had no sender in the mail. Thank you Share this post Link to post Share on other sites