I tried a ton of different ways to fix this issue, when I try to send the email if I fill the value 'name' just with one word it pass through and the email is sent. But if the 'name' value contains more than 1 word the error message shows up.
<?php
if( !isset($_POST['name']) || empty($_POST['name']) ||
!isset($_POST['phone']) || empty($_POST['phone']) ||
!isset($_POST['email']) || empty($_POST['email']) ||
!isset($_POST['asunto']) || empty($_POST['asunto']) ||
!isset($_POST['mensaje']) || empty($_POST['mensaje'])
){
echo '<p>Please fill in all fields</p>';
}else{
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$asunto = $_POST['asunto'];
$mensaje = $_POST['mensaje'];
$to = 'mail@hotmail.com';
$from = 'From:' . $name . '';
$subject = 'Mensaje de ' . $name . '';
$message = 'Nombre: ' . $name . '<br/><br/>
Telefono: ' . $phone . '<br/><br/>
Correo electronico: ' . $email . '<br/><br/>
Asunto: ' . $asunto . '<br/><br/>
Mensaje: ' . nl2br($mensaje) . '<br/>';
if (mail ($to, $subject, $message, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
Try this:
$from = 'From: ' . $name. ' <' . $email . '>' . "
" . 'X-Mailer: PHP';
RiggsFolly was correct there was an error in the following line
Invalid
$from = 'From:' . $name . '';
Valid
$from = 'From: ' . $email . '';
</div>