0

I'm trying to make a contact form in HTML page. I've linked it with a .php file and but both on a server but I don't receive any email. Someone can see my mistake?

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Contact form tutorial</title>
</head>

<body>
  <main>
    <p>SEND EMAIL</p>
    <form action="contactform.php" method="post">
      <input type="text" name="name" placeholder="Full name">
      <input type="text" name="mail" placeholder="Your e-mail">
      <input type="text" name="subject" placeholder="subject">
      <textarea name="message" placeholder="Message"></textarea>
      <button type="submit" name="submit">SEND MAIL</button>
    </form>
  </main>
</body>

</html>
<?php 
if (isset($_POST['submit'])) { 
    $name = $_POST['name']; 
    $subject = $_POST['subject']; 
    $mailFrom = $_POST['mail']; 
    $message = $_POST['message']; 
    $mailTo = "MINE@EMAIL.COM"; 
    $headers = "From: ".$mailFrom; 
    $txt = "You have received an e-mail from ".$name.".\n\n" . $message;
    mail($mailTo, $subject, $txt, $headers); 
    header("Location: index.php?mailsend"); }
Dave
  • 5,108
  • 16
  • 30
  • 40
  • 1
    Check the returned value from your call to the `mail()` function. "Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise." – Alex Howansky Sep 11 '19 at 17:41

1 Answers1

0

I think the issue is with your headers. I altered your script to conform the headers to the docs and it worked. I also sent a version with no headers and it worked as well.

$name = 'name'; 
$subject = 'subject'; 
$mailFrom = 'MINE@EMAIL.COM'; 
$message = 'message'; 
$mailTo = 'me@realaddress.com'; 
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$txt = "You have received an e-mail from ".$name.".\n\n".$message; 
mail($mailTo, $subject, $txt, $headers);
Mike Volmar
  • 1,927
  • 1
  • 22
  • 31