我有一张联系人表格,到目前为止工作得很好.然而,由于我在网站上创建了一个php路由,在提交表单后,尽管它重定向到action站点(Thank-you.php),但该站点的内容只是一个空白页面(正文中没有HTML内容,我使用dev工具进行了判断),消息也没有到达适当的邮箱地址.如果我在表单提交页面上var_ump$_POST变量,则不会显示任何值.
我怀疑问题与路由有关.作为测试,我在每条路由前放了一个带有升序数字的"print"PHP命令.我把感谢页(表单提交页)直接放在索引页后面,以排除代码是否在其他路由上卡住了.奇怪的是,尽管每个子页面只打印到给定页面在路由中的位置的数字,但感谢页面打印出所有数字,即那些也只会在队列中紧随其后的数字……如果能在这个问题上得到一些帮助,我将非常感激.提前谢谢您.
超文本标记语言(表单):
<form class="contact-form" method="POST" action="/thank-you">
<input type="text" id="website" name="website" />
<div class="contact-wrapper name">
<label for="name">
<?php echo $lang["contact-name"] ?>
</label>
<input type="text" id="name" name="name" placeholder="<?php echo $lang['name-placeholder'] ?>" required>
</div>
<div class="contact-wrapper email-and-phone">
<div>
<label for="email">E-mail</label>
<input type="text" id="email" name="email" placeholder="<?php echo $lang['email-placeholder'] ?>" required>
</div>
<div>
<label for="telephone">
<?php echo $lang["contact-telephone"] ?>
</label>
<input type="text" id="telephone" name="telephone" placeholder="<?php echo $lang['telephone-placeholder'] ?>">
</div>
</div>
<div class="contact-wrapper subject">
<label for="subject">
<?php echo $lang["contact-subject"] ?>
</label>
<input type="text" id="subject" name="subject" placeholder="<?php echo $lang['subject-placeholder'] ?>" required>
</div>
<div class="contact-wrapper message">
<label for="message">
<?php echo $lang["contact-message"] ?>
</label>
<textarea id="message" name="message" placeholder="<?php echo $lang['message-placeholder'] ?>" style="height:200px" required></textarea>
</div>
<input type="submit" id="submit" name="submit" value="<?php echo $lang['contact-submit'] ?>">
</form>
PHP(表单提交页面):
<?php
// exit if accessed directly.
defined('ABSPATH') || die(header('location: /home'));
if (isset($_POST['submit']) && $_POST['submit'] != '' && $_POST['submit'] != null) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$telephone = $_POST['telephone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "myemailaddress@gmail.com";
$txt = "You have received an e-mail from " . $name . ".\n\n" . "E-mail: " . $mailFrom . ".\n\n" . "Telephone: " . $telephone . ".\n\n" . $message;
mail($mailTo, $subject, $txt);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='UTF-8' />
<title>Thank you!</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="thank-you-wrapper">
<p>Thank you for reaching out to us. We will get back to you shortly. Please click <a href="/home" style="text-decoration: none; color: #0986d9;">here </a> if you are not redirected within a few seconds.
</p>
</div>
<script>
setTimeout(function() {
window.location.replace("/home"); // will redirect to main page
}, 3000); // will call the function after 3 secs.
</script>
</body>
</html>
PHP(路由):
<?php
require_once __DIR__ . '/router.php';
// ##################################################
// ##################################################
// ##################################################
// Static GET
// In the URL -> http://localhost
print '1';
// The output -> Index
get('/', 'pages/index.php');
print '2';
// The output -> Thank You
get('/thank-you', 'pages/thank-you.php');
print '3';
// The output -> About
get('/about', 'pages/about.php');
print '4';
// The output -> Services
get('/services', 'pages/services.php');
print '5';
// The output -> Web
get('/web', 'pages/web.php');
print '6';
// The output -> Contact
get('/contact', 'pages/contact.php');
``````````````````````````````````````````````````````