christo Posted April 30, 2006 Share Posted April 30, 2006 I'm trying to make work a script from this site's (members) tutorials ...http://www.phpfreaks.com/tutorials/40/8.php to learn how the mail function works but i keep getting 2 errors [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Notice: Undefined variable: pass in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 48Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 74Your password has been sent! Please check your email![/quote]Finally the 2 files: PasOub.html[code]<html> <form method="post" action="PasOub.php"> <table width="50%" border="0" cellspacing="0" cellpadding="4"> <tr><td>Please enter your email address</td> <td><input name="email" type="text"></td></tr> <tr><td> </td> <td><input name="recover" type="hidden" value="recover"> <input type="submit" name="Submit" value="Recover My Password!"></td></tr> </table> </form></html>[/code] PasOub.php[code]<?session_start();$email = $HTTP_POST_VARS['email'];$host = "???;$user = "???";$pass = "???";$base = "???";$db_conx = mysql_connect($host,$user,$pass) or print("erreur de connection mysql");mysql_select_db($base, $db_conx) or print("erreur connection base");switch($_POST['recover']){default:include 'PasOub.html';break;case "recover":recover_pw($_POST['email']);break;}function recover_pw($email){if(!$email){echo "You forgot to enter your Email address<strong>Knucklehead</strong><br />";include 'PasOub.html';exit();}// quick check to see if record exists$sql_check = mysql_query("SELECT * FROM user WHERE email='$email'");$sql_check_num = mysql_num_rows($sql_check);if($sql_check_num == 0){echo "No records found matching your email address<br />";include 'PasOub.html';exit();}// Everything looks ok, generate password, update it and send it!function makeRandomPassword() {$salt = "abchefghjkmnpqrstuvwxyz0123456789";srand((double)microtime()*1000000);$i = 0;while ($i <= 7) {$num = rand() % 33;$tmp = substr($salt, $num, 1);$pass = $pass . $tmp;$i++;}return $pass;}$random_password = makeRandomPassword();#$db_password = md5($random_password);#$sql = mysql_query("UPDATE user SET password='$password'#WHERE email='$email'");$subject = "Your Password at MyWebsite!";$message = "Hi, we have reset your password.New Password: $random_passwordhttp://www.mywebsite.com/login.phpThanks!The WebmasterThis is an automated response, please do not reply!";mail($email, $subject, $message, "From: MyDomain Webmaster<admin@mydomain.com>\nX-Mailer: PHP/" . phpversion());echo "Your password has been sent! Please check your email!<br />";}?>[/code]Of course the mail is not sent and i spent aloooot of time working out diffrent things ...i'm using php 4.3. on windows and i added the line smtp_port=25 at the php.ini do i need to add anything else ? why it doesn't understand $pass ?Christos Quote Link to comment Share on other sites More sharing options...
.josh Posted May 1, 2006 Share Posted May 1, 2006 first of all, it really helps when you put a little note in the code you post which line is for instance, 48, as described in your error message. just so you know. as to your first error:Notice: Undefined variable: pass in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 48$pass = $pass . $tmp; is your problem. you have not set $pass to anything and now you are trying to add $tmp to it. you will need to initialize it before the while loop before you can add stuff to it.2nd:#$sql = mysql_query("UPDATE user SET password='$password'#WHERE email='$email'");even though you didn't mention this, i thought i should point out that you are setting password to $password which doesn't exist. i think you probably meant#$sql = mysql_query("UPDATE user SET password='$random_password'#WHERE email='$email'"); Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 1, 2006 Share Posted May 1, 2006 The main reason why your're geting the following error message:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 74[/quote]is becuase your havn't setup PHP to use an SMTP Server. PHP needs to be pointed to an SMTP server in order to send the emails, with out an SMTP server your emails are going no where!To setup up PHP to use an SMTP server you'll need to edit your php.ini file and find the following line:[code]SMTP = localhost[/code]Change localhost to the smtp address. The address will be like the following: [i]smtp.hostname.com[/i]. Usually you'll find your ISP will have an SMTP server you can use.Once you have applied the changes save your php.in file and restart Apache Quote Link to comment Share on other sites More sharing options...
christo Posted May 1, 2006 Author Share Posted May 1, 2006 Hmm it's not very clear ...at the tutorial (http://www.phpfreaks.com/tutorials/40/8.php)they don't seem to initialise $pass with something and it still works...for other users :)So i keep getting this[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Notice: Undefined variable: pass in c:\foreign\easyphp1-8\www\agence\test\pasoub.php on line 48[/quote]Any other ideas ???P.S Otherwise the 2 tips about the database and the php.ini -> corrected Thumbs up !!!christos Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 1, 2006 Share Posted May 1, 2006 Others may not get the notice message becuase they may have error reporting turned off or is set not report any notice errors.Now the reason why you are getting the notice error is becuase when php goes through the while loop for the first time in the makeRandomPassword function the $pass variable doesn't actually exist, until the it loops through the secound time.To stop php from displaying the message either place the @ symbol in front of $pass like so:[code]@$pass = $pass . $tmp;[/code]or first create the $pass variable with a blank value before the while loop like so:[code]$pass = "";while ($i <= 7) {[/code] Quote Link to comment Share on other sites More sharing options...
christo Posted May 1, 2006 Author Share Posted May 1, 2006 It worked even with the pass problem finally but i leant something new too !!! So problem solved :-)Thanks christos Quote Link to comment 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.