Not able to make $http post request, getting undefined for $_POST["name"] in php and for all other posted data. but in my console printing all the data correctly, can u help me where I did mistake. I am sending data when click event is triggered, I am new to angular, please help me to solve this problem, Thanks to 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 like below
require ('smtp_lib/phpmailer.php');
require ('smtp_lib/smtp.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "yyyyyy";
$mail->FromName = $_POST["name"];
$mail->Subject = $_POST["subject"];
$mail->AddAddress("[email protected]");
$mail->AddReplyTo($_POST["mail"]);
$mail->Body = $_POST["message"].'<br>'.$_POST["no"];
$mail->AddAttachment($_POST["attach"]);
$mail->Send();
if I open php_error_log I 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
var_dump($_POST)and share the result$post = json_decode(file_get_contents('php://input'), true); var_dump($post);