Mahbubur Rahman Khan Mahbubur Rahman Khan - 14 days ago 6
AngularJS Question

PHP can't read email address from $http post method of angular

Everything works fine except email address. When i post email address to server and just echo it, recieve nothing. Only problem in @ symbol, rest are ok.

angular:

$http({
method: 'POST',
url: 'http://______.org/_____.php',
data: {
signInSubmitBTN: '', email: 'joe@g.com'
}
}).success(function (data) {
alert(data); //alert empty when joe@g.com but joeg.com is ok
});


PHP

if (isset($_POST['signInSubmitBTN'])) {

$email = $_POST["email"];

echo $email;


NOTE - already configure app

app.config(function ($httpProvider, $httpParamSerializerJQLikeProvider) {
$httpProvider.defaults.transformRequest.unshift($httpParamSerializerJQLikeProvider.$get());
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
})

Answer

You need to encode using base64:

signInSubmitBTN: '',  email: window.btoa('joe@g.com')

And don't forget to decode on the server side using atob()