Angularjs post to PHP

I have this console error.

POST http://localhost:8100/send.php 404 (Not Found)

And these is my script JS

And script PHP send.php

Someone can help me?. Thanks.

send.php is obviously not available on http://localhost:8100/send.php - that’s what the Error message 404 - Not Found is telling you.

Is this both on the same computer?
Can you open http://localhost:8100/send.php in a normal browser?

Yes, There are in the same computer.

And when I try to put the url. The script of send.php it download automatically.I can’t open it in the browser.

The is this POST http://localhost:8100/php/send.php 404 (Not Found).

Ah wait. 8100 is the port of ionic serve. And now I also see that the php folder is part of your ionic project.

You have to put the PHP script into another folder that is served by a webserver. Ionic won’t take care of that. Mobile app (Ionic) and backend app (PHP via Webserver) are two different projects.


It’s true. One more last question. I collocated the php file in the web serve, but it show me this error.

“XMLHttpRequest cannot load http://localhost/php/correo.php. Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.”

I don’t know. Maybe need add some more to my php file?

Thanks. Sujan12

Search CORS php htaccess
its will get help

1 Like

This should help:

  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Headers: Authorization, Content-Type');
header('Access-Control-Allow-Origin: *');
1 Like

You need to have a PHP server up and running, for a quick solution on windows install LAMP and drop the file where it tells you.

Then you need to enter the full url of the file, should be something like, lamp will guide you.

Then you will most likely face a CORS issue (maybe not since it’s localhost), but if you get error codes 0 try @Sujan12’s solution

Hi guys, Really I can’t solve it. And these is my code.

This is my angular code:

var app = angular.module(‘starter’, [‘ionic’]);


var config = {

$scope.sendemail = function(){
    var response = $http(config);


This is my php file (It is in the server):

<? php

message = "email: "._POST[“correo”];
$message = htmlspecialchars($mensaje);
$message = stripslashes($mensaje);

$to = "";
$subject = “You have new email”;
$header = "";
$enviar = mail($to,$subject,$message,$header);


And this is the error.

Do you believe could you help me? … Thanks a lot! :grin:

Just copy the code I posted on line two of your PHP - done.


Try to put this in your php file

<?php header("access-control-allow-origin: *"); ?>

or this in .htaccess file

<ifModule mod_headers.c> Header set Access-Control-Allow-Origin: * </ifModule>

1 Like