0

i can not get mail from forgot_password.php why? I use a free hosting.

<?php



// Require the configuration before any PHP code as the configuration controls error reporting:
require ('./includes/config.inc.php');
// The config file also starts the session.

// Include the header file:
$page_title = 'Forgot Your Password?';
include ('./includes/header.html');

// Require the database connection:
require ('./includes/mysql.inc.php');

// For storing errors:
$pass_errors = array();

// If it's a POST request, handle the form submission:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

	// Validate the email address:
	if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
	
		// Check for the existence of that email address...
		$q = 'SELECT id FROM users WHERE email="'.  mysqli_real_escape_string ($dbc, $_POST['email']) . '"';
		$r = mysqli_query ($dbc, $q);
		
		if (mysqli_num_rows($r) == 1) { // Retrieve the user ID:
			list($uid) = mysqli_fetch_array ($r, MYSQLI_NUM); 
		} else { // No database match made.
			$pass_errors['email'] = 'The submitted email address does not match those on file!';
		}
		
	} else { // No valid address submitted.
		$pass_errors['email'] = 'Please enter a valid email address!';
	} // End of $_POST['email'] IF.
	
	if (empty($pass_errors)) { // If everything's OK.

		// Create a new, random password:
		$p = substr(md5(uniqid(rand(), true)), 15, 15);

		// Update the database:
		$q = "UPDATE users SET pass='" .  get_password_hash($p) . "' WHERE id=$uid LIMIT 1";
		$r = mysqli_query ($dbc, $q);
		
		if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
		
			// Send an email:
			$body = "Your password to log into <whatever site> has been temporarily changed to '$p'. Please log in using that password and this email address. Then you may change your password to something more familiar.";
			mail ($_POST['email'], 'Your temporary password.', $body, 'From: northherner@hotmail.com');
			
			// Print a message and wrap up:
			echo '<h3>Your password has been changed.</h3><p>You will receive the new, temporary password via email. Once you have logged in with this new password, you may change it by clicking on the "Change Password" link.</p>';
			include ('./includes/footer.html');
			exit(); // Stop the script.
			
		} else { // If it did not run OK.
	
			trigger_error('Your password could not be changed due to a system error. We apologize for any inconvenience.'); 

		}

	} // End of $uid IF.

} // End of the main Submit conditional.

// Need the form functions script, which defines create_form_input():
require ('./includes/form_functions.inc.php');
?><h3>Reset Your Password</h3>
<p>Enter your email address below to reset your password.</p> 
<form action="forgot_password.php" method="post" accept-charset="utf-8">
	<p><label for="email"><strong>Email Address</strong></label><br /><?php create_form_input('email', 'text', $pass_errors); ?></p>
	<input type="submit" name="submit_button" value="Reset &rarr;" id="submit_button" class="formbutton" />
</form>

<?php // Include the HTML footer:
include ('./includes/footer.html');
?>
2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by labise
0

Do you actually see the message "Your password has been changed..."? If yes, then try adding a "To" header as well:

...
		if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.
		        $headers="";
		        $headers.="From: northherner@hotmail.com".PHP_EOL;
		        $headers.="To: ".$_POST['email'].PHP_EOL;

			// Send an email:
			$body = "Your password to log into <whatever site> has been temporarily changed to '$p'. Please log in using that password and this email address. Then you may change your password to something more familiar.";
			mail($_POST['email'], 'Your temporary password.', $body, $headers);
			
			// Print a message and wrap up:
			echo '<h3>Your password has been changed.</h3><p>You will receive the new, temporary password via email. Once you have logged in with this new password, you may change it by clicking on the "Change Password" link.</p>';
			include ('./includes/footer.html');
			exit(); // Stop the script.
			
		}
...
0

i tried another script but it doesn't send e-mail too

<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();

//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'lafamosa_kermis', 'lafamosa1980') or die(mysql_error());
$db = mysql_select_db('lafamosa_mystore', $con) or die(mysql_error());

//include out functions file giving us access to the protect() function made earlier
include "./functions.php";

?>
<html>
	<head>
		<title>Login with Users Online Tutorial</title>
		<link rel="stylesheet" type="text/css" href="style.css" />
	</head>
	<body>
		<?php
		
		//Check to see if the forms submitted
		if($_POST['submit']){
			//if it is continue checks
			
			//store the posted email to variable after protection
			$email = protect($_POST['email']);
			
			//check if the email box was not filled in
			if(!$email){
				//if it wasn't display error message
				echo "<center>You need to fill in your <b>E-mail</b> address!</center>";
			}else{
				//else continue checking
				
				//set the format to check the email against
				$checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
				
				//check if the email doesnt match the required format
	            if(!preg_match($checkemail, $email)){
	            	//if not then display error message
	                echo "<center><b>E-mail</b> is not valid, must be name@server.tld!</center>";
	            }else{
	            	//otherwise continue checking
	            	
	            	//select all rows from the database where the emails match
	            	$res = mysql_query("SELECT * FROM `users` WHERE `email` = '".$email."'");
	            	$num = mysql_num_rows($res);
	            	
	            	//check if the number of row matched is equal to 0
	            	if($num == 0){
	            		//if it is display error message
						echo "<center>The <b>E-mail</b> you supplied does not exist in our database!</center>";
					}else{
						//otherwise complete forgot pass function
						
						//split the row into an associative array
						$row = mysql_fetch_assoc($res);
						

						//send email containing their password to their email address
						mail($email, 'Forgotten Password', "Here is your password: ".$row['password']."\n\nPlease try not too lose it again!", 'From: northherner@hotmail.com');
						
						//display success message
						echo "<center>An email has been sent too your email address containing your password!</center>";
					}
				}
			}
		}
		
		?>
		<div id="border">
			<form action="forgot.php" method="post">
				<table cellpadding="2" cellspacing="0" border="0">
					<tr>
						<td>Email: </td>
						<td><input type="text" name="email" /></td>
					</tr>
					<tr>
						<td colspan="2" align="center"><input type="submit" name="submit" value="Send" /></td>
					</tr>
					<tr>
						<td colspan="2" align="center"><a href="register.php">Register</a> | <a href="login.php">Login</a></a></td>
					</tr>
				</table>
			</form>
		</div>
	</body>
</html>
0

I ask again, Do you actually see the message "Your password has been changed..."?
If yes:
a.) check your spam folder
b.) ask your web host if "free" account holders are allowed to send out emails - they may have this restriction.

Edited by hielo: n/a

0

"Your password has been changed" yes i get it i think the problem cause hosting company i adjust mail setting in cpanel but i can get or send e-mail.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.