-1

I am trying to send mail to my account using PHP but it show HTTP ERROR 405 when i submit my HTML form. Here's my HTML form:

<form action="spledmailer.php" method="post" enctype="text/plain" class="needs-validation" novalidate>
      <div class="container text-center w-50">
        <input type="text" class="form-control" placeholder="Enter Your Name" name="name" required><br>
        <input type="email" class="form-control" placeholder="Enter Your E-mail" id="email" name="Email" required><br>
        <textarea class="form-control" rows="5" placeholder="Tell Us About Your Request" name="query" required></textarea>
      </div>
      <div class="container" style="margin-top: 3%;">
        <div class="row">
            <div class="col text-center">
                <button type="submit" class="btn btn-outline-dark">Send Query</button>
            </div>
        </div>
      </div>
    </form>

And here's my PHP code:

if(isset($_POST['submit'])) {
    $to = "example@gmail.com";
    echo $subject = "Form Tutorial";
    echo $name_field = $_POST['name'];
    echo $email_field = $_POST['Email'];
    echo $message = $_POST['query'];

    $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

    echo "Data has been submitted to $to!";
    mail($to, $subject, $body);
} else {
    echo "blarg!";
}
nick
  • 77
  • 3
  • 13

1 Answers1

0

If you are using a web host, you might want to ask them if they block POSTing to certain files, or just the php mail function in general. This has been a problem for me in the past, so contact their support.

Also, make sure you enable error reporting or look through your error log. That can probably tell you what the problem is. See here: How can I get useful error messages in PHP?

Zach P.
  • 342
  • 1
  • 10