0

I am trying to implement forgot password feature using php mail feature.

I am using xampp and mac os 10.9.4

I get response as 1 and there is no error message too. But the mail isn't sent.

Following is the code:

<?php
// error_reporting(E_ALL);
$response = array();
require_once __DIR__.'/db_connect.php';
$db = new DB_CONNECT();
if(isset($_POST['email'])){
    $to = $_POST['email'];
    $subject = "Password recovery";
    $res = mysql_query("select password from userMaster where email_id = '$to'");
    if($res){
        $pwd="";
        while($row=mysql_fetch_array($res)){
            $pwd = $row['password'];
            // echo $pwd." ".$to;
        }
        $result = mail($to, $subject,$pwd);
        echo $result; die;
        if($result){
            $response["success"]=1;
            $response["message"]="Mail sent successfully";
        } else {
            print_r(error_get_last()); echo $result; die;
        }
    }else {
        $response["success"] = 0;
        $response["message"] = "Error sending mail";
        //echo mysql_error(); die;
    }
}else {
    $response["success"] = 0;
    $response["message"] = "Missing parameters";
}
echo json_encode($response);
?>

I googled and found a number of solutions but none worked in my favor. Where am I getting wrong? How do I solve this?

Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104
z22
  • 10,013
  • 17
  • 70
  • 126

1 Answers1

0

It won't work on localhost. Try it on a free hosting website and it will work.

akshaynagpal
  • 2,965
  • 30
  • 32