I have a contact form but it does not send if there are accents or ñ, I have tried in several ways but I have not been able to send the form if they put accents, symbols or ñ. I don't know what could be missing, add UTF8 but nothing every time someone fills out the form and places some special character the form doesn't arrive and presents errors.
<form action="sendbymail2.php" method="post" accept-charset="ISO-8859-1">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="contact-form-textfield pb-4">
<input type="text" placeholder="Nombre" class="form-control" required="" name="nombre">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="contact-form-textfield pb-4">
<input type="email" name="email" placeholder="Email" class="form-control" required="">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="contact-form-textfield pb-4">
<input type="tel" name="phone" placeholder="Celular" class="form-control">
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="contact-form-textfield pb-4">
<input type="text" name="direccion" placeholder="Dirección" class="form-control" >
</div>
</div>
<div class="col-lg-12">
<div class="contact-form-textfield pb-4">
<textarea placeholder="Mensaje - agregar placa si eres conductor" class="form-control message" name="message"></textarea>
</div>
</div>
<div class="col-lg-12 pt-xs-25px text-center">
<input id="submit" type="submit" class="btn btn-success" name="submit" value="Enviar mensaje" />
</div>
</div>
</form>
sendbymail2.php
<?php
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$direccion = $_POST['direccion'];
$message= $_POST['message'];
$para = '[email protected]';
$titulo = 'Hola- Contactenos ';
$header = 'From: ' . $email;
$headers .= "Content-Type: text/html; charset=\"utf-8\"";
$msjCorreo = "Nombre: $nombre\n E-Mail: $email\n Celular: $phone\n Direccion: $direccion\n Mensaje: $message\n";
if ($_POST['submit']) {
if (mail($para, $titulo, $msjCorreo, $header)) {
echo "<script language='javascript'>
window.location.href = 'https://www.mipagina.com';
</script>";
} else {
echo 'Falló el envio';
}
}
?>
You have to use the mb_send_mail function, which encodes the message to utf-8, as indicated in the official php documentation https://www.php.net/manual/es/function.mb-send-mail.php
Also in your form change the accept-charset because you have it to english, or omit it.