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

PHP邮件表单无法发送邮件且触发404错误的问题排查求助

PHP邮件表单无法发送邮件且触发404错误的问题排查求助

各位好,我现在遇到了PHP邮件表单的棘手问题,想请大家帮忙排查下哪里出了错。我有index.php和contactform.php两个文件,确认它们在同一个正确的文件夹里,表单能正常显示,但点击「SEND MAIL」按钮后完全没反应,浏览器控制台还抛出了404错误(状态码HTTP/2 404,传输605B,Referrer Policy为strict-origin-when-cross-origin)。我试过调整input type="email"的写法,也检查了代码里的分号,但问题还是没解决。

先把我的代码贴出来:

index.php 代码

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
    <link="stylesheet" href="index.css">
    <!-- zde doplnit odkaz na CSSka -->
</head>
<body>
    <p>SEND E-MAIL</p>
    <form class="contact-form" action="contactform.php" method="post">
        <input type="text" name="name" placeholder="Full name">
        <input type="email" name="mail" placeholder="Your-email">
        <input type="text" name="subject" placeholder="Subject">
        <textarea name="message" placeholder="Message"></textarea>
        <button type="submit" name="submit">SEND MAIL</button>
    </form>
</body>
</html>

contactform.php 代码

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

    $mailTo = "acme@proton.me";
    $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");
}
?>

我现在的几个疑问:

  • 明明两个文件在同一文件夹,为什么会触发404错误?是不是表单的action路径哪里写错了?
  • 除了404的问题,我的邮件发送逻辑本身有没有漏洞?比如mail()函数的参数、请求参数的获取是否正确?
  • 会不会是服务器环境的问题(比如PHP的mail配置未启用),但现在得先解决404的问题,毕竟表单提交都没到达处理页面。

麻烦各位帮我分析下,谢谢!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.07 13:14:50