簡體   English   中英

無法解決“無法 POST /contact.php”錯誤

[英]Can't solve "Cannot POST /contact.php" ERROR

我不斷收到錯誤“無法 POST /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 上提交表單時,用戶的姓名、電子郵件和消息會通過電子郵件發送到我的個人電子郵件。 請幫忙。 非常感激!!

如果 index.html 和 contact.php 在文件夾中的位置相同,那么您應該從 action 中刪除前導斜杠。

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

/作為路徑中的第一個字符用於絕對路徑(從系統根目錄開始的路徑)。

因此,如果contact.php位於表單頁面所在的同一目錄中,請嘗試以下操作:

action="contact.php"

否則指定這樣的相對路徑:

action="subDir/subDir2/contact.php"
// or
action="../otherDir/contact.php"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM