php - 无法解决“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 上提交表单时,用户的姓名、电子邮件和消息都会通过电子邮件发送到我的个人电子邮件。请帮忙。非常感激!!
解决方案
如果 index.html 和 contact.php 在文件夹中的位置相同,那么您应该从操作中删除前导斜杠。
如果这不起作用,请在 domain.com/contact.php 中添加完整的 url
推荐阅读
- sql - 搜索存储过程并返回搜索参数存在于字符串 ('') 中的存储过程
- mysql - MYSQL 中的错误 1022“无法在表中写入重复键”。奇怪的部分是其他我用相同的方式创建了其他表
- coinbase-api - Coinbase API 交易历史
- c# - 如何使用带有 2 个表的 Sql 连接,但 table2 具有多对一关系
- c++ - Visual Studio“项目+项目”问题
- mysql - 如何在 MySQL RDS 中使用 GROUP_CONCAT 创建超链接?
- google-apps-script - 如何通过 Google 表格中的 URL 导入 XLSX 文件(已更新)?
- javascript - Discord.js Covid Tracker 命令
- java - 如何在 Java 中使用 Retrofit 解析嵌套的多个 Json 对象
- ios - 强制 Unity iOS 应用程序崩溃以进行 Crashlytic 仪表板测试