0

I'm having some difficulty getting my contact form working on my website. It opens a blank page and actually doesn't work at all. My code is below:

<form action="mail.php" method="post" class="comment-form">
<input name="name" type="text" placeholder="Your Name" required>
<input name="email" type="email" placeholder="Email">
 <input type="url" placeholder="Website">
<textarea rows="4" placeholder="Messages"></textarea>
 <input type="submit" value="send message">                                     
 </form>

And php code:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Website'; 
$to = 'me@me.com'; 
$subject = 'Email Inquiry';

$header = "From: noreply@example.com\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n"; 

mail($to, $subject, $message, $headers);
header("location: ../contact");
?>

2 Answers2

-1

Use this to send your cod to the php instead of just refreshing

    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method='POST'>
panda
  • 1
  • 2
-1

There is nothing in your form with the name 'submit'. You have type="submit". So your code is not going in the if the condition of if($_POST['submit']).

You should check for something else. Like: if ($_POST['name']) or if ($_POST['email']).

Also, I would suggest having an else block for your - if ($_POST['name']) so you can show some message instead of getting a blank page.

Shaunak Sontakke
  • 980
  • 1
  • 7
  • 17