I am developing a website with html, css, js. I have a tab with contact. I would like to send an email from the contact form to my email address with the details. Searching on the internet I can see that there is a php function, so I used it. I can see that the mail()
function returns 1 but I don't receive the email. Any ideas? How can I solve this problem?
<?php
if (isset($_POST['name']) &&
isset($_POST['email']) &&
isset($_POST['subject']) &&
isset($_POST['mensaje']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$to = 'prueba@gmail.com';
$subject = $_POST['subject'];
$mensaje = $_POST['mensaje'];
$body = '<html>
<body>
<h2>Ha rellenado el formulario de contacto en la web</h2>
<hr>
<p>Nombre:<br>'.$name.'</p>
<p>Email:<br>'.$email.'</p>
<p>Asunto:<br>'.$subject.'</p>
<p>Mensaje:<br>'.$mensaje.'</p>
</body>
</html>';
//headers
$headers = "From: ".$name." <".$email.">\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8";
//send
$send = mail($to, $subject, $body, $headers);
if($send){
echo '<br>';
echo 'ha funcionado';
}else{
echo 'no ha funcionado';
}
}
?>