Jump to content

Not sending me email


ch4rlie

Recommended Posts

I am creating a forgotten password button, it works but it just doesn't send me an email containing the reset link.

Here's the code for the email part:

<?php

require("../config.php");

if($_GET['code'])
{
	$get_username = $_GET['username'];
	$get_code = $_GET['code'];
	
	$query = mysql_query("SELECT * FROM users WHERE username='$get_username'");
	
	while($row = mysql_fetch_assoc($query))
	{
		$db_code = $row['passreset'];
		$db_username = $row['username'];
	}
	if($get_username == $db_username && $get_code == $db_code)
	{
		echo "
		
		<form action='pass_reset_complete.php?code=$get_code' method='POST'>
			Enter a new password<br><input type='password' name='newpass'><br>
			Re-enter your password<br><input type='password' name='newpass1'><p>
			<input type='hidden' name='username' value='$db_username'>
			<input type='submit' value='Update Password!'>
		</form>
		
		";
	}
	
}

if(!$_GET['code'])
{
echo "

<form action='forgot_pass.php' method='POST'>
	Enter your username<br><input type='text' name='username'><p>
	Enter your email<br><input type='text' name='email'><p>
	<input type='submit' value='Submit' name='submit'>
</form>

";

if(isset($_POST['submit']))
{
	$username = $_POST['username'];
	$email = $_POST['email'];
	
	$query = mysql_query("SELECT * FROM users WHERE username='$username'");
	$numrow = mysql_num_rows($query);
	
	if($numrow!=0)
	{
		while($row = mysql_fetch_assoc($query))
		{
			$db_email = $row['email'];
		}
		if($email == $db_email)
		{
			$code = rand(10000,1000000);
			
			$to = $db_email;
			$subject = "Password Reset";
			$body = "
			
			This is an automated email. Please DO NOT reply to this email.
			
			Click the link below or paste it into your browser
			http:/www.***REMOVED***.com/second/forgot_pass.php?code=$code&username=$username
			
			";
			
			mysql_query("UPDATE users SET passreset='$code' WHERE username='$username'");
			
			mail($to,$subject,$body);
			
			echo "Check Your Email";
		}
		else
		{
			echo "Email is incorrect";	
		}
	}
	else
	{
		echo "That username doesnt exist";	
	}
}
}
?>
Link to comment
https://forums.phpfreaks.com/topic/292683-not-sending-me-email/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.