Search code examples
phpformssyntaxxampp

PHP: syntax error, unexpected token "<" (<bold>)


I'm trying to validate a form via PHP, but I get a syntax error (unexpected token "<") that I can't solve. Here is the code. The error is apparently in line 4 (which is the first bold):

<?php
if(isset($_POST['email'])) {

<bold>// Debes editar las próximas dos líneas de código de acuerdo con tus preferencias</bold>
$email_to = "xxxx";
$email_subject = "xxxx";

<bold>// Aquí se deberían validar los datos ingresados por el usuario</bold>
if(!isset($_POST['nombre']) ||
!isset($_POST['correo']) ||
!isset($_POST['xx']) ||
!isset($_POST['xx'])) {

echo "<b>Ocurrió un error y el formulario no ha sido enviado. </b><br />";
echo "Por favor, vuelva atrás y verifique la información ingresada<br />";
die();
}

$email_message = "Detalles del formulario de contacto:\n\n";
$email_message .= "Nombre: " . $_POST['nombre'] . "\n";
$email_message .= "Correo: " . $_POST['correo'] . "\n";
$email_message .= "xx: " . $_POST['xx'] . "\n";
$email_message .= "xx: " . $_POST['xx'] . "\n\n";


<bold>// Ahora se envía el e-mail usando la función mail() de PHP</bold>
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

echo "¡El formulario se ha enviado con éxito!";
}
?>

I've already edited the Short Tag to "On" in php.ini and it didn't fix it, what is that I'm not seeing here?


Solution

  • <bold> is HTML, not a valid PHP construct.

    You can have HTML in the same file, although, not usually best practice unless it is a template, but you must close the PHP tag (<?php ... ?><bold><?php ...) before writing the HTML.

    I'm not sure the purpose of your <bold> tags in this code, however. It seems like an oversight.