What a good day, I have the following code in PHP:
<div class="wrap">
<form id="ContactForm" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<label>Asunto:</label>
<input type="text" class="form-control" id="asunto" name="asunto" placeholder="Asunto:" value="<?php if(!$enviado && isset($asunto)) echo $asunto ?>">
<label>E-mail:</label>
<input type="text" class="form-control" id="email" name="email" placeholder="E-mail:" value="<?php if(!$enviado && isset($email)) echo $email ?>">
<label>Mensaje:</label>
<textarea name="mensaje" class="form_control" id="mensaje" placeholder="Escribe aqui tu mensaje"></textarea>
<?php if(!empty($errores)): ?>
<div class="alert error">
<?php echo $errores; ?>
</div>
<?php elseif ($enviado): ?>
<div class="alert exito">
<p>Enviado Correctamente</p>
</div>
<?php endif ?>
<input type="submit" name="submit" class="btn btn_primary" value="Enviar Correo"></input>
</form>
In the part of the programming I have the following:
<?php
$errores='';
$enviado='';
$mensaje_enviar='';
if (isset($_POST['submit'])) {
$asunto=$_POST['asunto'];
$email=$_POST['email'];
$mensaje=$_POST['mensaje'];
if (!empty($asunto)) {
$asunto=trim($asunto);
$asunto=filter_var($asunto, FILTER_SANITIZE_STRING);
}else{
$errores='Por favor ingresa un nombre <br />';
}
if (!empty($email)) {
$email=filter_var($email, FILTER_SANITIZE_EMAIL);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$errores .='Por favor ingresa un correo valido <br />';
}
}else{
$errores .='Por favor ingresa un correo <br />';
}
if (!empty($mensaje)) {
$mensaje=htmlspecialchars($mensaje);
$mensaje=trim($mensaje);
$mensaje=stripcslashes($mensaje);
}else{
$errores .='Por favor ingresa el mensaje <br />';
}
if (!$errores) {
$destinatario='[email protected]';
$asunto='Correo enviado desde';
$mensaje_enviar="Asunto:" .$asunto;
$mensaje_enviar.="E-mail:" .$email;
$mensaje_enviar.="Mensaje:" . $mensaje;
mail($destinatario, $asunto, $mensaje_enviar);
$enviado=true;
}
}
require 'Contacto.view.php';
?>
And it throws me the following error that I will attach in an image:
Could you help me with this code? The variable where the error marks me is already defined.