0

I'm trying to make a very basic contact form using HTML and PHP. For some reason, however, when I click the "submit" button I get the error "405 Not Allowed". Why? How could I fix this? (I'm hosting my website on GitHub)

my HTML:

<!DOCTYPE html>
<html>


<head>
    <title></title>
</head>
<body>

    <form action="send_form_email.php" method="POST">
            <input type="text" name="name" placeholder="Full Name">
            <input type="text" name="mail" placeholder="Your e-mail">
            <input type="text" name="subject" placeholder="Subject">
            <textarea name="message" placeholder="Message"></textarea>
            <button type="submit" name="submit">Send e-mail</button>
    </form>

</body>


</html>

my PHP:

<?php

if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];


$mailTo = "example@gmail.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;

mail($mailTo, $subject, $txt, $headers);
header("Location: index.php?mailsend");
}

(PS. I wrote "example@gmail.com" just because I wanted to keep my personal e-mail private on here.

PPS. I have been trying to make a very simple contact form (you write your name mail and message and the owner of the website receives it in the inbox) but none of my (desperate) attempts seems to work. Can anyone help me out?)

tommsyeah
  • 17
  • 2
  • 9
  • This is not going to be a problem with code, it will be a problem with your webserver/hosting... "The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the request method is known by the server but has been disabled and cannot be used." – Scuzzy Mar 19 '18 at 22:10
  • As I said, I am hosting my website on github. How can avoid this problem? (after all, I need to try out the code to see if it works! Won't Github let me do it?) – tommsyeah Mar 19 '18 at 22:11
  • "As I said" no you didn't. All I can tell you is the simple nature of that code is not going to generate a 405 error, and that the issue lays elsewhere. – Scuzzy Mar 19 '18 at 22:12
  • I'm very sorry I thought I'd written it! Sorry about this. – tommsyeah Mar 19 '18 at 22:13
  • Yes, github only permit static pages... however I found this: https://stackoverflow.com/questions/24348223/send-email-from-static-page-hosted-on-github-pages there are a few client side suggestions in that thread. – Scuzzy Mar 19 '18 at 22:16
  • FYI https://help.github.com/articles/what-is-github-pages/ "GitHub Pages is a static site hosting service and doesn't support server-side code such as, PHP, Ruby, or Python." – Scuzzy Mar 19 '18 at 22:23
  • ouch! what a pity.. how do you think I could try out my code and see if it works if I can't host the website on GitHub? Do you know of any free way of doing this? – tommsyeah Mar 19 '18 at 22:31
  • No sorry, I'm not up to speed with free hosting offerings. The link above had some solutions for contact forms. – Scuzzy Mar 19 '18 at 22:33

1 Answers1

3

Github is a hosting service for static web pages. PHP is not static. Deploying PHP to GitHub Pages - is it possible?