Viro Laruga
Viro Laruga

Reputation: 1

Why this PHP code to redirect form it's not working?

I've used this php code before on another landing page and couldn't work better, but now I'm using it on a landing page hosted on a sub-domain and it's not working. Both archives the index.php and the thank-you-page.html are storaged on the same folder.

Heres the code.

<div id="forma" class="col-2">
        <?php
            $action=$_REQUEST['action'];
            if ($action=="")
            {
            ?>
        <form action="" method="POST" enctype="multipart/form-data">
        <input type="hidden" name="action" value="submit">
            <p>Nombre</p> <input type="text" name="name"/>
            <p>Apellidos</p> <input type="text" name="surname"/>
            <p>Email</p> <input type="text" name="email">
            <p>Tel&eacute;fono</p> <input type="text" name="phone" maxlength="12"/>
            <input type="submit" value="Enviar" name="submit"/><input type="reset" value="Limpiar">
            <?php
            include "include/thank-you-page.html";
            ?>
        </form>
        <?php
        }
         else if($_POST['email'] == '' or !preg_match("/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/",$_POST['email'])){
        echo "Favor de ingresar un correo válido <a href=\"\">en la forma</a>";}
        else
        {
        $name=utf8_decode($_POST['name']);
        $surname=utf8_decode($_POST['surname']);
        $email=$_POST['email'];
        $phone=$_POST['phone'];
        $message="
        APC Back-UPS Landing page:
        Nombre: $name
        Apellidos: $surname 
        e-mail: $email 
        telefono: $phone";
        if(($name=="")||($email=="")||($phone==""))

        {
            echo "Favor de llenar los campos requeridos <a href=\"\">en la forma</a>";
        }

        else
        {
        $from="From: $name<$email>\r\nReturn-path: $email";
        $subject = "Landing page Back-UPS";
        mail("[email protected]", $subject, $message, $from);
        header('Location: http://www.securepowersolutions.com.mx/backups/thank-you-page.html');
            }
        }
        ?>

Any ideas about why it's not answering?

Upvotes: 0

Views: 64

Answers (1)

Mr. Llama
Mr. Llama

Reputation: 20899

From the documentation for header:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

You have HTML output before your call to header.

Upvotes: 1

Related Questions