0

Hi im new to PHP and i'am having issues sending an email. Im getting the following message when i trigger the funtion with axios:

Access to XMLHttpRequest at 'myServer/EinladungMail.php' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
quasar.esm.js?b178:6 POST myServer/EinladungMail.php net::ERR_FAILED

my php code:

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT');
header('Access-Control-Allow-Headers: Content-Type');
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
$mail = $_POST["mail"];
$message= 'myMessage';
$headers = 'From: noreply@company.com';
$mail($mail, 'Einladung', $message, $headers );

JS:

 if (this.ValidateEmail()) {
        axios({
          method: 'post',
          url: 'myserver/EinladungMail.php',
          data: {
            mail: this.mail2
          }
        }).then(response => {
          console.log(response)
          window.alert('einladung gesendet')
        }
        ).catch(
          error => {
            window.alert(error.message)
          }
        )
      }

thanks in advance

Joh
  • 1
  • 1
    Have you read up on how to properly implement CORS in PHP? Are you handling the `OPTIONS` HTTP method? Are there other headers you need to allow? – T.J. Crowder Aug 20 '20 at 14:18
  • You can disable cors in chrome https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome – arman amraei Aug 20 '20 at 14:56

0 Answers0