我有一张联系人表格,到目前为止工作得很好.然而,由于我在网站上创建了一个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');
``````````````````````````````````````````````````````

推荐答案

路由将/thank-you定义为GET:

get('/thank-you', 'pages/thank-you.php');

当您的表格通过POST发送时:

<form class="contact-form" method="POST" action="/thank-you">

Php相关问答推荐

为什么PHP输出\n而不是实际创建一个新元素?

wp_enqueue_scripts not loading(基于类的插件)

如果再次调用SESSION_START(),会话.gc-max是否会重新启动?或者它是从第一次创建会话开始计算的?

Symfony/Panther Web抓取不适用于登录后的内容(云功能)

如何使用ms graph php sdk v2列出具有已知路径的DriveItem的子项

根据WooCommerce中的客户计费国家/地区更改产品价格

如何从WooCommerce checkout 帐单邮箱字段中删除星号?

如何使用定制的StateProvider设置JsonLd@上下文?

使用CODIGNITER3中的OR和AND子句进行查询

SFTP在PHP(phpseclib3\Net\SFTP)-过滤目录列表结果服务器端可能吗?类似于psftp中的LS命令?

使用随机生成器在MYSQL中创建唯一ID-定义一个数组来存储已知ID是否安全

向WooCommerce管理订单总额添加自定义总额行

对 WooCommerce 购物车和 checkout 中显示的运输方式进行排序

如何将不同的 Woocommerce 费用合并为一个名称?

如何处理 Null 上的 array_shift() ?

根据WooCommerce中的产品重量更改简单产品的输入数量步值

在WooCommerce购物车和 checkout 页面中更改总计文本

WooCommerce订单支付页面上的附加支付订单按钮

Laravel 响应 html 默认页面忽略控制器

mysql / sql修复多对多数据库中的行