I've been stuck on this for days.
Basically I have a $http.post with Angular, posting an e-mail address and message to be emailed from post.php. Post.php is then echoing text depending on the result of the mail(), but when I return
Success
for example, it will actually show the HTML on the DOM instead of process it.Appreciate any help.
app.controller('contactsController', function($scope, $rootScope, $http) {
$rootScope.currentPage = "contact";
$scope.postData = {};
$scope.data = "Send";
$scope.runScript = function() {
$http({
url: "post.php",
method: "POST",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $.param({"postData":$scope.postData})
}).success(function(data) {
$scope.data = data;
console.log(data);
$scope.contactForm.$valid = false;
}).error(function(data, status, headers, config) {
$scope.status = status;
});
};
});
<?php
// get the raw POST data
$inputData = $_POST['postData'];
if(isset($inputData["email"])&&isset($inputData["message"])) {
$email = $inputData["email"];
$message = $inputData["message"];
$to = "XXXXXXXXXXXXX@XXXXXXXXXX.COM"; // required
$from = $email; // required
$body = $message;
$subject = "Online Query Submission";
// create email headers
if(mail($to,$subject,$body,"From:$from/r/nReply-to:$from"))
echo "<p>Success - Thanks!</p>";
else
echo "<p>Error - Sorry!</p>";
}
?>