Ошибка синтаксиса: Неожиданное число в Object.parse, PHP для AngularJS

Я создал контактную форму, используя AngularjS для моего интерфейса и PHP для почтового клиента, который отправляет электронное письмо. Я хочу передать данные с PHP на Angular, сообщив Angular, отправлено ли электронное письмо. Однако, когда я пытаюсь это сделать, я получаю «Синтаксическая ошибка: Неожиданный номер».

Мой PHP:

<?php require_once "../vendors/PHPMailer-master/PHPMailerAutoload.php"; print_r($_POST); $data = array(); $sender_name = isset($_POST['sender_name']) ? $_POST['sender_name'] : ''; $sender_email = isset($_POST['sender_email']) ? $_POST['sender_email'] : ''; $sender_tel = isset($_POST['sender_tel']) ? $_POST['sender_tel'] : ''; $sender_message = isset($_POST['sender_message']) ? $_POST['sender_message'] : ''; $mail = new PHPMailer; //Enable SMTP debugging. $mail->SMTPDebug = 3; //Set PHPMailer to use SMTP. $mail->isSMTP(); //Set SMTP host name $mail->Host = "smtp.gmail.com"; //Set this to true if SMTP host requires authentication to send email $mail->SMTPAuth = true; //Provide username and password $mail->Username = "*****@gmail.com"; $mail->Password = "******"; //If SMTP requires TLS encryption then set it $mail->SMTPSecure = "tls"; //Set TCP port to connect to $mail->Port = 587; $mail->From = $sender_email; $mail->FromName = $sender_name; $mail->addAddress("blah@blah.com", "Blah"); $mail->isHTML(true); $mail->Subject = "Message Sent from jcrageralternatives.com by: ".$sender_name; $mail->Body = "<p>Name: ".$sender_name."</p><p>Email Provided: ".$sender_email."</p><p>Phone Number Provided: ".$sender_tel."</p><p>Message: '".$sender_message."'</p>"; $mail->AltBody = $sender_message; header('Content-Type: application/json'); if(!$mail->send()) { $data["success"] = false; } else { $data["success"] = true; } echo json_encode($data); ?> 

И мой контроллер:

 $http({ method : 'POST', url : '/php/contact.php', data : $.param($scope.contactData), // pass in data as strings headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload) }).then(function (response) { console.log(response.data); } }); 

Если я удалю header('Content-Type: application/json'); из файла PHP и еще console.log(response.data) , я получаю:

 2016-01-16 02:34:28 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ) 2016-01-16 02:34:28 Connection: opened 2016-01-16 02:34:29 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP ry1sm18220246pab.30 - gsmtp 2016-01-16 02:34:29 CLIENT -> SERVER: EHLO localhost 2016-01-16 02:34:29 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [73.15.255.61] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2016-01-16 02:34:29 CLIENT -> SERVER: STARTTLS 2016-01-16 02:34:29 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2016-01-16 02:34:29 CLIENT -> SERVER: EHLO localhost 2016-01-16 02:34:29 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [73.15.255.61] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2016-01-16 02:34:29 CLIENT -> SERVER: AUTH LOGIN 2016-01-16 02:34:29 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2016-01-16 02:34:29 CLIENT -> SERVER: dmliaHUxMjAxQGdtYWlsLmNvbQ== 2016-01-16 02:34:29 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2016-01-16 02:34:29 CLIENT -> SERVER: Q0BycGVEMWVt 2016-01-16 02:34:29 SERVER -> CLIENT: 235 2.7.0 Accepted 2016-01-16 02:34:29 CLIENT -> SERVER: MAIL FROM:<v@v> 2016-01-16 02:34:29 SERVER -> CLIENT: 250 2.1.0 OK ry1sm18220246pab.30 - gsmtp 2016-01-16 02:34:29 CLIENT -> SERVER: RCPT TO:<****@gmail.com> 2016-01-16 02:34:29 SERVER -> CLIENT: 250 2.1.5 OK ry1sm18220246pab.30 - gsmtp 2016-01-16 02:34:29 CLIENT -> SERVER: DATA 2016-01-16 02:34:29 SERVER -> CLIENT: 354 Go ahead ry1sm18220246pab.30 - gsmtp 2016-01-16 02:34:29 CLIENT -> SERVER: Date: Sat, 16 Jan 2016 02:34:28 +0000 2016-01-16 02:34:29 CLIENT -> SERVER: To: **** **** <****@gmail.com> 2016-01-16 02:34:29 CLIENT -> SERVER: From: v <v@v> 2016-01-16 02:34:29 CLIENT -> SERVER: Subject: Message Sent from jcrageralternatives.com by: v 2016-01-16 02:34:29 CLIENT -> SERVER: Message-ID: <421aa50e45d9e33b9b7c41918d99af59@localhost> 2016-01-16 02:34:29 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.14 (https://github.com/PHPMailer/PHPMailer) 2016-01-16 02:34:29 CLIENT -> SERVER: MIME-Version: 1.0 2016-01-16 02:34:29 CLIENT -> SERVER: Content-Type: multipart/alternative; 2016-01-16 02:34:29 CLIENT -> SERVER: boundary="b1_421aa50e45d9e33b9b7c41918d99af59" 2016-01-16 02:34:29 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: This is a multi-part message in MIME format. 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: --b1_421aa50e45d9e33b9b7c41918d99af59 2016-01-16 02:34:29 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: as;lkdfjas;ldkf 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: --b1_421aa50e45d9e33b9b7c41918d99af59 2016-01-16 02:34:29 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: <p>Name: v</p><p>Email Provided: v@v</p><p>Phone Number Provided: 1234567891</p><p>Message: 'as;lkdfjas;ldkf'</p> 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: --b1_421aa50e45d9e33b9b7c41918d99af59-- 2016-01-16 02:34:29 CLIENT -> SERVER: 2016-01-16 02:34:29 CLIENT -> SERVER: . 2016-01-16 02:34:30 SERVER -> CLIENT: 250 2.0.0 OK 1452911670 ry1sm18220246pab.30 - gsmtp 2016-01-16 02:34:30 CLIENT -> SERVER: QUIT 2016-01-16 02:34:30 SERVER -> CLIENT: 221 2.0.0 closing connection ry1sm18220246pab.30 - gsmtp 2016-01-16 02:34:30 Connection: closed {"success":true} 

Первое местоположение ошибки «Неожиданное число» после Objects.parse (native) находится в JSON из библиотеки AngularJS. Где неожиданный номер и что я могу сделать, чтобы исправить это, поэтому я могу прочитать response.data["success"] ?