0

I want to redirect my page after the script ends to other site using the code:

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

I got error in browser

Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/bootstrap/header.php:33) in /Applications/MAMP/htdocs/bootstrap/emailto.php on line 70

Please find below my code:

    <?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'); ?>
MrWhite
  • 43,179
  • 8
  • 60
  • 84
Denis Milosavljevic
  • 365
  • 4
  • 8
  • 17

3 Answers3

0

You've already sent data to the client. You must sent the headers before you sent anything at all.

Efekan
  • 1,497
  • 12
  • 31
0

simply copy your submit button code to top of the page before start any html means before include header.php file.

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...";
            }

        }
Rakesh Sojitra
  • 3,538
  • 2
  • 17
  • 34
0

Place your code before Html tag works as if html is getting before content will be sent and the header relocation will create a problem and won't work. Try using this as stated below.

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...";
        }

    }

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

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77