javascript - Angular $http post request undefined in PHP -
not able make $http
post request, getting undefined $_post["name"]
in php , other posted data. in console printing data correctly, can u me did mistake. sending data when click event triggered, new angular, please me solve problem, replies in advance.
angular.element(document.queryselector('#applyjob')).unbind('click').bind('click', function () { console.log($scope.username+$scope.useremail+$scope.usermobileno+$scope.subject+$scope.usercoverletter+$scope.attach); $http({ method: "post", url: "mailer.php", data: { name : $scope.username, mail : $scope.useremail, no : $scope.usermobileno, subject : $scope.subject, message : $scope.usercoverletter, attach : $scope.attach }, headers: {'content-type': 'application/x-www-form-urlencoded; charset=utf-8'} }); });
my php
code looks below
require ('smtp_lib/phpmailer.php'); require ('smtp_lib/smtp.php'); $mail = new phpmailer(); // create new object $mail->issmtp(); // enable smtp $mail->smtpdebug = 1; // debugging: 1 = errors , messages, 2 = messages $mail->smtpauth = true; // authentication enabled $mail->smtpsecure = 'ssl'; // secure transfer enabled required gmail $mail->host = "smtp.gmail.com"; $mail->port = 465; // or 587 $mail->ishtml(true); $mail->username = "xxx@gmail.com"; $mail->password = "yyyyyy"; $mail->fromname = $_post["name"]; $mail->subject = $_post["subject"]; $mail->addaddress("zzz@gmail.com"); $mail->addreplyto($_post["mail"]); $mail->body = $_post["message"].'<br>'.$_post["no"]; $mail->addattachment($_post["attach"]); $mail->send();
if open php_error_log
getting these errors
[29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: name in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 16 [29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: subject in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 17 [29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: mail in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 20 [29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: message in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 21 [29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: name in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 21 [29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: mail in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 21 [29-apr-2015 08:44:36 europe/berlin] php notice: undefined index: no in c:\xampp\htdocs\wwwroot\contact-form\files\contact_mailer.php on line 21
this known issue angular php can solve with;
var form = {name:"x",mail:"x",no:0,subject:"x",message:"x",attach:"x"}; var formdata = new form(); formdata.name = $scope.username, formdata.mail = $scope.useremail, formdata.no = $scope.usermobileno, formdata.subject = $scope.subject, formdata.message = $scope.usercoverletter, formdata.attach = $scope.attach $http({ method: "post", url: "mailer.php", data: formdata });
in php take file_get_contents("php://input")
;
$postdata = file_get_contents("php://input"); $formdata = json_decode($postdata); echo $formdata->name;
Comments
Post a Comment