When a reigster clicks to register I call a php script via an ajax request which creates the user and emails a notifcation:
$.ajax({
type: "POST",
dataType: "json",
data: dataString,
url: "includes/register-user.php",
success:function(result){
console.log('Success!);
}
});
MY php has an if statement on the mail send:
if($mail->Send()){
$reply = ['response'=> true, 'message' => 'User successfully registered'];
}
else{
$reply = ['response' => false, 'message' => 'An error has occurred'];
}
echo json_encode($reply);
The email is sent and received but the success function in the jQuery doesn't fire. There is no other output in the PHP and no errors, all I see is a JSON object:
{"response":true,"message":"User successfully registered"}
I've been dubugging this for 4 hours and it makes no sense whatsoever!
Update:
General:
Request URL:http://foo.bar/includes/email-register-confirm.php Request Method:POST Status Code:200 OK Remote Address:127.0.0.1:80 Referrer Policy:no-referrer-when-downgrade
Repsonse headers:
Connection:Keep-Alive Content-Length:85 Content-Type:text/html; charset=UTF-8 Date:Fri, 23 Jun 2017 14:12:43 GMT Keep-Alive:timeout=5, max=94 Server:Apache/2.4.23 (Win64) PHP/7.0.10 X-Powered-By:PHP/7.0.10
Update and Solution
I found that my phpmailer class was saved with BOM file settings which was adding a rougue\ufeff char to the beginning of my json reply!