PHP mail () method and response callback do not work

The script below is designed to send email to the registrant and reply success back to the page for certain actions, if sent by mail, anyway, if I added the php mail() method, the callback response no longer works, the email address was successfully delivered to mailbox, but I was not lucky to receive a success warning, as soon as I delete the mail() method, a success warning appears again, I received some tips on Json.response did not form, but I really do not know how this works, can anyone anything be able to do this, I only want to deliver mail and receive a β€œsuccessful” 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, resolving the found conflict to $message vs $message['success'] , I changed $message to something else.

Thanks for watching my post.

+4
source share
1 answer

You must set the json content type:

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

All Articles