Reputation: 1876
I have been building Ionic Mobile app with AngularJS. and im trying to send email form. PHP part is working fine. i tested it with parametered URL and it worked. but with the application its not working.
here my HTML part
<form>
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Name" ng-model="name">
</label>
<label class="item item-input">
<input type="text" placeholder="Email" ng-model="email">
</label>
<label class="item item-input">
<textarea row="10" cols="50" placeholder="Message" ng-model="message"></textarea>
</label>
<label class="item">
<button class="button button-block button-positive" ng-click="feedbacksubmit();">Submit</button>
</label>
</div>
</form>
and Here my ControllerJS part
$scope.feedbacksubmit= function (){
$scope.buttonclick() // to Check button has click (yes button works)
$http.post("http://boost.meximas.com/mobile/email.php?name="+name+"&email="+email+"&message="+message).success(function(data){
//$scope.tasks = data;
$scope.donemessage();
});
};
Here my PHP code
<?php
$name=$_GET['name'];
$email=$_GET['email'];
$message=$_GET['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill <a href=\"\">the form</a> again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("[email protected]", $subject, $message, $from);
echo "Email sent!";
}
?>
Upvotes: 0
Views: 2057
Reputation: 873
Sample Code and JsFiddle: http://jsfiddle.net/YGQT9/
app.controller('FormCtrl', function ($scope, $http) {
$scope.data = {
firstname: "default",
emailaddress: "default",
gender: "default",
member: false,
file_profile: "default",
file_avatar: "default"
};
$scope.submitForm = function() {
console.log("posting data....");
$http.post('http://posttestserver.com/post.php?dir=jsfiddle', JSON.stringify(data)).success(function(){/*success callback*/});
};
});
Upvotes: 1
Reputation: 27043
Try to post the data as a JSON object and pass it as the second argument for $http.post()
.
var data = {
name: 'foo bar',
email: '[email protected]'
};
$http.post("http://boost.meximas.com/mobile/email.php", data)
.success(function(data){
//$scope.tasks = data;
$scope.donemessage();
});
Upvotes: 1