javascript - Syntax error: Unexpected number at Object.parse, PHP to AngularJS -
i have built contact form using angularjs frontend , php mail client sends email. want pass data php angular, telling angular whether or not email sent. however, when try that, "syntax error: unexpected number".
my 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 use smtp. $mail->issmtp(); //set smtp host name $mail->host = "smtp.gmail.com"; //set true if smtp host requires authentication send email $mail->smtpauth = true; //provide username , password $mail->username = "*****@gmail.com"; $mail->password = "******"; //if smtp requires tls encryption set $mail->smtpsecure = "tls"; //set tcp port connect $mail->port = 587; $mail->from = $sender_email; $mail->fromname = $sender_name; $mail->addaddress("blah@blah.com", "blah"); $mail->ishtml(true); $mail->subject = "message sent 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); ?>
and controller:
$http({ method : 'post', url : '/php/contact.php', data : $.param($scope.contactdata), // pass in data strings headers : { 'content-type': 'application/x-www-form-urlencoded' } // set headers angular passing info form data (not request payload) }).then(function (response) { console.log(response.data); } });
if remove header('content-type: application/json');
php file , still console.log(response.data)
, get:
2016-01-16 02:34:28 connection: opening 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 @ 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 start tls 2016-01-16 02:34:29 client -> server: ehlo localhost 2016-01-16 02:34:29 server -> client: 250-smtp.gmail.com @ 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 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: 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}
the first location of unexpected number error, after objects.parse (native) @ fromjson angularjs library. unexpected number , can fix can read response.data["success"]
?
Comments
Post a Comment