在 PHP / HTML 表单上提交数据时出现 405 HTTP 错误

405 HTTP Error on submitting data on PHP / HTML form

我正在构建一个表单,填写的数据需要发送到电子邮件。我正在使用 HTML 和 PHP。但不幸的是,当我按下提交按钮时出现以下错误。

405 - HTTP verb used to access this page is not allowed. The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access

PHP代码是:

<?php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];
    
    $email_subject = "NEW MESSAGE VIA CONTACT FORM";
    
    $email_body = "You have received a new message from the user ".$name. ".\n".$message;
    
    $to = "info@house.gr"
    $headers = "From: ".$visitor_email;
    
    mail($to, $email_subject, $email_body, $headers);
    header("Location: index.html?mailsend");
}
?>

HTML 形式为:

<form method="POST" class="contact-form" actions="contactform.php">
                                <input type="text" name="name" placeholder="Full Name">
                                <input type="text" name="mobile" placeholder="Your Mobile Phone">
                                <input type="text" name="email" placeholder="Your E-mail">
                                <textarea class="materialize-textarea" name="message" placeholder="Your Message"></textarea>
                                <input type="submit" value="Submit" class="btn">
                            </form>

更新: 对代码进行此编辑:action="contactform.php" ,我没有收到错误,但电子邮件未发送

最终解决方案: 将 php 文件更改为:

    $headers = "From: ";
    $headers .= $visitor_email;
    
    mail($to, $email_subject, $email_body, $headers);
    header('Location: ../');

我通过网络服务器中的日志文件发现了问题

也许你在表单的属性中写了动作而不是动作

actions="contactform.php"

应该是

action="contactform.php"