Php 标题位置-此网页具有重定向循环

Php 标题位置-此网页具有重定向循环,php,wordpress,Php,Wordpress,嗨,我正试图重定向到一个表单页面,但是我收到了以下消息 ERR_TOO_MANY_REDIRECTS 我已经能够理解这一点 header('Location: http://localhost:8888/wordpress/send'); 是导致错误的原因我尝试了很多不同的方法,包括在最后一行代码下面添加exit,但它似乎仍然在循环 <?php /* Template Name: Send */ ?> <?php session_start

嗨,我正试图重定向到一个表单页面,但是我收到了以下消息

ERR_TOO_MANY_REDIRECTS
我已经能够理解这一点

header('Location: http://localhost:8888/wordpress/send');
是导致错误的原因我尝试了很多不同的方法,包括在最后一行代码下面添加exit,但它似乎仍然在循环

<?php
    /*
    Template Name: Send
    */
?>

<?php
    session_start();
    require_once(get_template_directory().'/vendor/PHPMailer/PHPMailerAutoload.php');


    $errors = [];

    if(isset($_POST['customername'], $_POST['email'], $_POST['message'])) {
        $fields = [
            'name' => $_POST['customername'],
            'email' => $_POST['email'],
            'message' => $_POST['message']
        ];

        foreach ($fields as $field => $data) {
            if (empty($data)) {
                  $errors[] = 'The ' . $field . ' field is required';
            }
        }
    } else {

        $errors[] = 'Something went wrong.';
    }

    header('Location: http://localhost:8888/wordpress/send');
    exit();


必须在条件块中移动
header()
函数。正如所写的,它总是被执行的。你能给我举个例子吗?如果表单没有返回错误会发生什么?重定向应该转到那里,但是如果没有错误,代码看起来不会执行任何操作http://localhost:8888/......
?在if check中的条件块中移动头在
foreach{…}if(count($errors)==0){header(…)}之后清空$errors
必须移动
头()
条件块中的函数。正如所写的,它总是被执行的。你能给我举个例子吗?如果表单没有返回错误会发生什么?重定向应该转到那里,但是如果没有错误,代码看起来不会执行任何操作http://localhost:8888/......?将if check中的条件块中的头移动到foreach{…}if(count($errors)==0){header(…)}之后的空$errors