PHP mail()方法和响应回调不起作用

Script below is purpose to send email to registrant and response success back to page for certain action if mailed, somehow if I added-in php mail() method, the callback response would not working anymore, the email was successfully delivered to the mailbox but I have no luck to get the success alert, once I remove the mail() method, the success alert is pop again, I got some hints on Json.response doesn't formed, but I really have no idea how is it work, can anyone pls help on this, what I want is only deliver a mail and get 'success' callback?

request.php

if(empty($fname) || strlen($fname) < 3){
    $message['error']['fname'] = 'Full name is required';
}
if(empty($contact)){
    $message['error']['contact'] = 'Contact number is required';
}

if(!isset($message['error'])){

    $create = "//sql for insertion";

    if($create){
    //problem is here
    $to = $email;
    $subject = "Email Validation";
    $message = "http://www.sitename.com/activate.php?token=".$activate_code;
    $from = "post@mail.com";
    $headers = "From:" . $from;

    if(mail($to,$subject,$message,$headers)){
        $message['success'] = "success";
    }

    }

    }
}
echo json_encode($message);

Thanks.

Update:

Finally solved by found conflict on $message vs $message['success'], I changed $message to something else.

Thanks viewing my post.

You have to set the content type to json:

header("Content-Type: application/json");
echo json_encode($message);