无法解决“无法发布/contact.php”错误

时间:2019-12-19 08:35:07

标签: php html

我不断收到错误消息“无法发布/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>");
}

?>

在发布网站之前,我正在使用Brackets Editor和Live Preview Option测试我的网站。

我想要这样做,以便当用户在index.html上提交表单时,会将用户的姓名,电子邮件和消息通过电子邮件发送到我的个人电子邮件中。请帮忙。非常感谢!

2 个答案:

答案 0 :(得分:0)

如果文件夹中index.html和contact.php的位置相同,则应从操作中删除前导斜线。

如果这样不起作用,请在该域中添加该domain.com/contact.php的完整网址

答案 1 :(得分:0)

/作为路径中的第一个字符用于绝对路径(从根系统目录开始的路径)。

因此,如果contact.php位于表单页面所在的目录中,请尝试以下操作:

action="contact.php"

否则请指定相对路径,如下所示:

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