0

Im making a web form using the following code that is down below:

<?php

$nombre = $_POST['nombre'];
$mail = $_POST['correo'];
$empresa = $_POST['mensaje'];
$telefono = $_POST['telefono'];

$header = 'From: ' . $mail . " \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";

$mensaje = "Este mensaje fue enviado por: " . $nombre . ",\r\n";
$mensaje .= "Su e-mail es: " . $mail . ",\r\n";
$mensaje .= "Su teléfono (y WhatsApp) es: " . $_POST['telefono'] . ",\r\n";
$mensaje .= "Mensaje: " . $_POST['mensaje'] . ". \r\n";
$mensaje .= "Consulta realizada el " . date('d/m/Y', time());

$para = 'there goes the mail, ofc';
$asunto = '¡Nuevo formulario de contacto!';

mail($para, $asunto, utf8_decode($mensaje), $header);
header("Location: contacto.html");
echo '<script language="javascript">alert("Su consulta ha sido enviada correctamente");</script>';

?>

The problem is on the last lines of codes, where Im actually trying to send a message to the sender that the mail has been sent succesfully.

I must also say, that I tried to put the echo before the header and it still not working.

2
  • 4
    You redirect away from the page before you echo that content. That's why you never see it. Commented Feb 27, 2021 at 22:37
  • after redirecting you can't echo anything Commented Feb 27, 2021 at 23:00

1 Answer 1

1

After the redirect, javascript codes won't work. The example below will guide you. First, it displays a alert message and then directs it.

echo '<script>alert("Your message"); window.location.href = "contacto.html";</script>'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.