首页 > 解决方案 > 无法解决“Cannot POST /contact.php”错误

问题描述

我不断收到错误“无法发布/contact.php”。请帮忙!!下面是我的代码

这是 index.html

<form action="/contact.php" method="post">
        <div class="w3-row-padding" style="margin:0 -16px 8px -16px">
          <div class="w3-half">
            <input class="w3-input w3-border" type="text" placeholder="Name" required name="sender">
          </div>
          <div class="w3-half">
            <input class="w3-input w3-border" type="text" placeholder="Email" required name="senderEmail">
          </div>
        </div>
        <input class="w3-input w3-border" type="text" placeholder="Message" required name="message">
        <button class="w3-button w3-black w3-right w3-section" type="submit" value="submit" name="submit">
          <i class="fa fa-paper-plane"></i> SEND MESSAGE
        </button>
      </form>

这是contact.php

<?php

if(isset($_POST["submit"])) {
    $recipient="my@email.addres";
    $subject="Email from Matabots Website";
    $sender=$_POST["sender"];
    $senderEmail=$_POST["senderEmail"];
    $message=$_POST["message"];

    $mailBody="Name: $sender\nEmail: $senderEmail\n\n$message";

    mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
}

?>

在发布之前,我正在使用括号编辑器和实时预览选项来测试我的网站。

我希望这样当用户在 index.html 上提交表单时,用户的姓名、电子邮件和消息都会通过电子邮件发送到我的个人电子邮件。请帮忙。非常感激!!

标签: phphtml

解决方案


如果 index.html 和 contact.php 在文件夹中的位置相同,那么您应该从操作中删除前导斜杠。

如果这不起作用,请在 domain.com/contact.php 中添加完整的 url


推荐阅读