Error 405 - Cross Domain Request

0

Well, I was requesting my page from github (tiagosilveiaa.gihub.io) to my test server, just to execute the Script itself, but I was presented with a message that the protocols were different ( https x http) "" I have resolved "" by putting the address as follows:

Cod:

//tiagotestes.esy.es/portfolio/php/envia.php

Now I get the message 405, that the method is invalid. How can I solve this? Because I can do POST from my localhost.

Form:

<form id="contato" action="//tiagotestes.esy.es/portfolio/php/envia.php" method="POST">

JS:

$("#enviar").click(function() {
    if (validar()){
        $.post(
                $("#contato").attr("action"),
                $("#contato").serialize()
            )
            .done(function(retorno) {
                alert(retorno);
                $("#nome").val("");
                $("#email").val("");
                $("#telefone").val("");
                $("#mensagem").val("");

            })
            .fail(function(retorno) {
                alert(retorno)
            });
      }
});

PHP:

<?php
header('Access-Control-Allow-Origin: https://tiagosilveiraa.github.io/');
header('Access-Control-Allow-Methods: POST');
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$nome = $_POST["nome"];
$email = $_POST["email"];
$telefone = $_POST["telefone"];
$mensagem = $_POST["mensagem"];

if ($nome ==""){
  echo("Preencha o campo nome");
  die();
} else if ($email ==""){
  echo("Preencha o campo E-Mail");
  die();
} else if ($telefone ==""){
  echo("Preencha o campo Telefone");
  die();
} else if ($mensagem ==""){
  echo("Preencha o campo Mensagem");
  die();
}

$msgfinal = "Oi, você recebeu uma mensagem enviada pelo formulário do Site<br />
                Esses são os dados do cliente:
                <ul>
                <li><h3>Nome: ". $nome. "</h3></li>
                <li><h3>E-Mail: " .$email. "  </h3></li>
                <li><h3>Telefone: ".$telefone." </h3></li>
                </ul>
                <br />
                <p>
                Essa é a mensagem que ele mandou: <br/><br/><blockquote style='border-left: solid 5px #f7ca18; padding-left: 10px;'><i> &nbsp; " .$mensagem.
                "</i></blockquote></p>" ;

// send email
mail("[email protected]","Contato do Site", $msgfinal, $headers);
?>
    
asked by anonymous 19.04.2017 / 03:33

1 answer

0

Usually 405 indicates preflight / OPTIONS request, in which the request is being rejected by the server itself, nor does it reach php or anything else it is using. You have to change apache or .htaccess settings

    
19.04.2017 / 13:00