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.
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
This should help:
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization, Content-Type');
exit;
}
header('Access-Control-Allow-Origin: *');
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 127.0.0.1/yourfile.php, 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â]);
app.controller(âsend_emailâ,function($scope,$http){
var config = { method:'POST', url:'http://www.hobbylacuesta.com/correo.php', data:'correo=alexis.970991@gmail.com', headers:{'Content-Type':'application/x-www-form-urlencoded'} } $scope.sendemail = function(){ var response = $http(config); response.success(function(data,status){ console.log('Done'); }); response.error(function(data,status){ console.log('Error'); }); }
});
This is my php file (It is in the server):
<? php
$message = "email: ".$_POST[âcorreoâ];
$message = htmlspecialchars($mensaje);
$message = stripslashes($mensaje);
$to = âalexis.970991@gmail.comâ;
$subject = âYou have new emailâ;
$header = âFrom:alexis.970991@gmail.comâ;
$enviar = mail($to,$subject,$message,$header);
?>
And this is the error.
Do you believe could you help me? ⌠Thanks a lot!
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>