You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP表单提交出现HTTP 405错误的问题求助

PHP表单提交出现HTTP 405错误的问题求助

我最近在测试一个简单的表单提交功能,预期提交后会跳转到成功页或者错误页,但现在每次提交都会返回HTTP 405错误。所有文件都放在网站根目录下,下面是我用到的全部代码,麻烦各位帮忙看看哪里出问题了?

表单页面(index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>
<body>
    <form action="send_email.php" method="post" target="_blank">
        <!-- 表单字段 -->
        <input type="email" name="email" required placeholder="email"/>
        <input type="text" name="subject" required placeholder="subject" />
        <textarea name="message" placeholder="message"></textarea>
        <button type="submit">Submit</button>
    </form>
</body>
</html>

邮件处理脚本(send_email.php)

<?php 
// send_email.php 
$to = "mail@example.com"; // 替换为自己的邮箱
$subject = $_POST["subject"]; 
$body = $_POST["message"]; 

// 使用原生PHP mail()函数发送邮件(也可以用PHPMailer这类库)
if (mail($to, $subject, $body, "From: " . $_POST["email"])) { 
    header("Location: success.php"); // 跳转至成功页
    exit; 
} else { 
    // 发送失败时跳转至错误页
    header("Location: error.php"); 
    exit; 
} 
?>

成功页面(success.php)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>success</h1>
</body>
</html>

错误页面(error.php)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <H1>error</H1>
</body>
</html>

我已经确认所有文件路径都正确,表单的请求方法也是POST,实在搞不懂为什么会出现405错误,有没有可能是服务器配置的问题?或者脚本里有什么我没注意到的细节?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 08:24:32