Page redirection error - PHP

Asked

Viewed 35 times

0

I have a form that sends an email message. It turns out that the code I have here does not seem to be working the redirect part to confirmation page or sending error:

<?php

// Destinatário:
$para = "[email protected]";
// Assunto:
$assunto = "ASSUNTO X";
// Data de Envio:
$data_envio = date("d/m/Y h:i:s");

// Dados do Formulário:
$email = $_POST["email"];
$mensagem = "MSG X";
$mensagem .= "Enviado em $data_envio.";

$headers = "MIME-Version: 1.1\r\n"; 
$headers .= "Content-Type:text/html; charset=UTF-8\r\n";
$headers .= "From: $para\r\n";
$headers .= "Return-Path: $para\r\n";
$headers .= "Reply-To: $email\r\n";

$envio = mail($para, $assunto, $mensagem, $headers);

        if($envio) {
            header("location:respostaform_ok.html");
        }
        else {
            header("location:respostaform_erro.html");
        }       

?>

I can receive the message by email, but the user sending the msg cannot see the confirmation page.

Could someone help? Thank you.

  • You can’t have any output before the header function, so make sure you don’t have echo, var_dump, or print_r inside your mail function. And give an Exit right after the header.

1 answer

-2

Have with your site’s full url instead of using:

header("location:respostaform_ok.html");

Use like this:

header("location:http://seu-site.com.br/respostaform_ok.html");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.