Using PHP to send a reply from a form to my Email and is giving the error 405 Not Allowed

0

Every time I click to submit the form it gives this error! How can I resolve this?

HTML Form Code 5:

<form class = "col s12 m4 offset-m4 l4 offset-l4" action="submit_form.php" method="post">

    <div class="row">

        <div class="input-field col s12">
            <i class="material-icons prefix sKtq-scColor">&#xE87C;</i>
            <input id="icon_prefix" name="Nome" type="text" class="validate sKtq-scColor" required>
            <label for="icon_prefix" class = "sKtq-scColor">Nome</label>
        </div>

        <div class="input-field col s12">
            <i class="material-icons prefix sKtq-scColor">&#xE0BE;</i>
            <input id="icon_prefix" name="Email" type="email" class="validate sKtq-scColor" required>
            <label for="icon_prefix" class = "sKtq-scCo lor">Email</label>
        </div>

        <div class="input-field col s12">
            <i class="material-icons prefix sKtq-scColor">sort</i>
            <input id="icon_prefix" name="Assunto" type="text" class="validate sKtq-scColor" required>
            <label for="icon_prefix" class = "sKtq-scColor">Assunto</label>
        </div>

        <div class="input-field col s12">
            <i class="material-icons prefix sKtq-scColor">chat_bubble</i>
             <textarea id="textarea1" name="Mensagem" class="materialize-textarea validate sKtq-scColor" required></textarea>
             <label for="textarea1" class = "sKtq-scColor">Mensagem</label>
        </div>

    </div>

    <br>

    <div class = "center-align">

        <button class="btn waves-effect waves-light sKtq-bgScColor" type="submit"> Enviar
            <i class="material-icons right">send</i>
        </button>

    </div>

</form>

PHP code that is in the file submit_form.php :

<?php

if(isset($_POST['email'])) {
    $email_to = "mtqr1@hotmailcom";
    $email_subject = "Mensagem do site";
    $name = $_POST['Nome']; // required
    $email_from = $_POST['Email']; // required
    $subject = $_POST['Assunto']; // required
    $message = $_POST['Mensagem']; // required

    function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message = "Form details below.\n\n";
    $email_message .= "Name : ".clean_string($name)."\n";
    $email_message .= "Email : ".clean_string($email_from)."\n";
    $email_message .= "Assunto : ".clean_string($subject)."\n";
    $email_message .= "Mensagem : ".clean_string($message)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
  <!-- include your own success html here -->

  <div class="feedback">Thank you for contacting us. We will be in touch with you very soon.</div>

  <?php
}
?>

Image of the error

    
asked by anonymous 25.12.2017 / 19:42

1 answer

1

In the github documentation, more specifically in What is GitHub Pages? , it is clear that you can not run a PHP script. Only static documents such as html, css, and javascript are supported.

The full quote is this:

  

GitHub Pages is a static site hosting service and does not support   server-side code such as PHP, Ruby, or Python.

In Portuguese:

  

GitHub Pages is a static website hosting service and does not   supports server-side code such as PHP, Ruby or Python.

This means that when you make a POST request, it is blocked by default, returning error 405, since it was set in the server settings, since there is no reason to allow this since only static pages are served .

You can even access the file using a GET request (just enter an url when the error message appears), but the plain text content of your file will be returned (nothing will be interpreted). >

To be able to run your script to some alternatives:

  • Buy a hosting (for the whole site or just for the specific script)
  • Or use a free hosting just for the file to send email (there is a link in the github page), although the free hosting block the sending of emails.
25.12.2017 / 23:43