0

I am trying to build a website where people can upload notes and anyone can download it. For anyone to upload there is a provision for sign up and login. There is also a forgot password link which does the following : 1.Asks user emial id 2.checks if it is in the database 3.If yes then sends a mail with the change password link to that mail-id. I've tried using lamp server and also hosted it on 2freehosting.com . But the mail isn't getting sent. The message error is being displayed on the screen.The code is here! any help on this will be greatly appreciated. Thank you.

<!DOCTYPE html>
    <html>
    <head>
        <title>Forgot Password</title>
    </head>
    <body>
        <?php 
        error_reporting(0);
        $email=$_POST['email'];
        if($_POST['submit']=='Send')
        {
            /* Attempt MySQL server connection. Assuming you are running MySQL server */

            $link = mysqli_connect("localhost", "root", "", "demo");
            // Check connection
            if($link === false){
                die("ERROR: Could not connect. " . mysqli_connect_error());
            }
            $query="SELECT * from persons where email_address='$email'";
            $result=mysqli_query($link,$query) or die(error);
            if(mysqli_num_rows($result))
            {
                $message="You activation link is: http://link/for/changing/password.php?email=$email";
                mail($email, "Subject Goes Here", $message);
                $Message = "Email sent";
                header("Location:login.php?Message=".$Message);
                die;
             }
            else
            {
                echo "No user exist with this email id";
            }
        }
    ?>
    <form action="forgot.php" method="post">
        Enter you email ID: <input type="text" name="email">
        <input type="submit" name="submit" value="Send">
    </form>
   </body>

1 Answers1

1

Use this code,

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($email, "Subject Goes Here", $message, $headers);
Mansoor H
  • 594
  • 1
  • 8
  • 25