I am trying to send request with Axios to my backend server (PHP 8.1) with this part of code
axios.post('https://mydomainfake.org/send_message.php', {
email: getValues("email"),
}).then(function (response) {
console.log(response);
})
and I receive every time this error message
Access to XMLHttpRequest at 'https://mydomainfake.org/send_message.php' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
Any how how to send data successful?
And I am using cloudflare and have SSL from ZeroSSL
My cors on backend php server
<?php
header("Accept: *");
header("Content-Type: multipart/form-data");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PUT");
header('Content-Type: text/html; charset=utf-8');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}
and my package.json
{
"name": "website",
"version": "1.0.0",
"private": true,
"homepage": "/",
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
},
}
}