Kevin Aartsen Kevin Aartsen - 5 months ago 11
HTML Question

Whats wrong with my code

I have a form which is supposed to send me an email when filled. For some reason it gives me the succes message but when i go to my email to check nothing is there, I can't seem to find where i messed up.
Im still a php newby any help with additional information is more than welcome I just wanna learn from my mistakes.

Html:

<form class="form-style-4" action="contact-back.php" method="post">

<span>Enter Your Name</span>
<input type="text" name="field1" required="true" />


<span>Email Address</span>
<input type="email" name="field2" required="true" />


<span>Short Subject</span>
<input type="text" name="field3" required="true" />


<span>Message to Us</span>
<textarea name="field4" onkeyup="adjust_textarea(this)" required="true"></textarea>

<button class="button">Verzend</button>
</form>


php:

<?php
$name = $_POST['field1'];
$email = $_POST['field2'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Dit adres klopt niet";
die();
}


$bericht = $_POST['field4'];

$to = "flash1996mph@hotmail.com";
$subject = $_POST['field3'];
$body = array("name", "email", "onderwerp", "bericht");
mail($to, $subject, $body);

echo "U bent succesvol aangemeld voor de Vandenberg nieuwsbrief";
?>

Answer

try this working fine in my localhost

$name = $_POST['field1'];
$email = $_POST['field2'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo "Dit adres klopt niet";
  die();
}


$bericht = $_POST['field4'];

$to = "flash1996mph@hotmail.com";
$subject = $_POST['field3'];
$message="something content";
$body = array("name", "email", "onderwerp", "bericht");
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";



mail($to,$subject,$message,$headers);


echo "U bent succesvol aangemeld voor de Vandenberg nieuwsbrief";
Comments