[英]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.