PHP标头重定向错误

时间:2016-01-11 11:15:15

标签: php

我希望在脚本结束后使用代码将页面重定向到其他网站:

header("Refresh:3; url=http://www.googe.com");

我在浏览器中出错了

  

警告:无法修改标头信息 - 已在第70行的/Applications/MAMP/htdocs/bootstrap/emailto.php中发送的标头(在/Applications/MAMP/htdocs/bootstrap/header.php:33处开始输出)< / p>

请在下面找到我的代码:

    <?php include('header.php'); ?>
  <!-- Sidebar -->
        <div id="sidebar-wrapper">
            <?php include('links.php'); ?>
        </div>
        <!-- /#sidebar-wrapper -->


     <!-- Page Content -->
        <div id="page-content-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">

                        <form class="form-horizontal" role="form" method="post" action="">
                                <div class="form-group">
                                    <label for="to" class="col-sm-2 control-label">To</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="to" name="to" placeholder="To" value="<?php echo $_REQUEST['emails']; ?>">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="Subject" class="col-sm-2 control-label">Subject</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="subject" name="subject" placeholder="subject" value="subject">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="message" class="col-sm-2 control-label">Message</label>
                                    <div class="col-sm-10">
                                        <textarea class="form-control" rows="4" name="message"></textarea>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-10 col-sm-offset-2">
                                        <input id="submit" name="submit" type="submit" value="Send email" class="btn btn-primary">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-10 col-sm-offset-2">
                                        <! Will be used to display an alert to the user>
                                    </div>
                                </div>
                        </form>

                         </div>
                </div>
            </div>
        </div>
        <!-- /#page-content-wrapper -->
        <div class="container-fluid">
        <?php



            if(isset($_REQUEST['submit'])) {

                    $to = $_REQUEST['to'];
                    $subject =$_REQUEST['subject'];
                    $body= $_REQUEST['message'];
                    $from= "admin@vision.com";
                    $headers= "From: $from";

                if($to && $subject && $body) {

                    mail($to, $subject, $body, $headers);
                    echo "your email has been sent!";
                    header("Refresh:3; url=http://www.googe.com");


                } else {

                    echo "please fill up all fields...";
                }

            }



        ?>


    </div> <!-- end of div container -->



    <?php include('footer.php'); ?>

3 个答案:

答案 0 :(得分:0)

您已将数据发送给客户。您必须在发送任何内容之前发送标题。

答案 1 :(得分:0)

只需将提交按钮代码复制到页面顶部,然后在包含header.php文件之前启动任何html方法。

dpkg -S /usr/lib/apache2/modules/mod_log_sql.so

答案 2 :(得分:0)

在Html标记工作之前放置代码就像在发送内容之前获取html并且标头重定位将产生问题而无效。 尝试使用如下所述。

if(isset($_REQUEST['submit'])) {
            $to = $_REQUEST['to'];
            $subject =$_REQUEST['subject'];
            $body= $_REQUEST['message'];
            $from= "admin@vision.com";
            $headers= "From: $from";

        if($to && $subject && $body) {

            mail($to, $subject, $body, $headers);
            echo "your email has been sent!";
            header("Refresh:3; url=http://www.googe.com");


        } else {

            echo "please fill up all fields...";
        }

    }

..... ....... .........