My PHP script doesn't send mail. What's wrong? Do I need headers or other things? Is mail not supported?
PHP code:
<?php
if(isset($_POST['submit'])){
$to = "mymail@gmail.com"; // this is your Email address
$from = $_POST['mail']; // this is the sender's Email address
$voornaam = $_POST['voornaam'];
$achternaam = $_POST['achternaam'];
$telefoon = $_POST['telefoon'];
$personen = $_POST['personen'];
$datum = $_POST['datum'];
$tijd = $_POST['tijd'];
$opmerking = $_POST['opmerking'];
$subject = "Reservering via Website";
$subject2 = "KOPIE: Reservering bij .....";
$message = "Voornaam: " . $voornaam . "\n\n" . "Achternaam: " . $achternaam . "\n\n" . "Telefoon: " . $telefoon . "\n\n" . "E-Mail: " . $from . "\n\n" . "Aantal Personen: " . $personen . "\n\n" . "Datum: " . $datum . "\n\n" . "Tijd: " . $tijd . "\n\n" . "\n\n" . "Opmerking:" . "\n\n" . $opmerking;
$message2 = "Hartelijk dank voor uw reservering." . "\n\n" . "Voornaam: " . $voornaam . "\n\n" . "Achternaam: " . $achternaam . "\n\n" . "Telefoon: " . $telefoon . "\n\n" . "E-Mail: " . $from . "\n\n" . "Aantal Personen: " . $personen . "\n\n" . "Datum: " . $datum . "\n\n" . "Tijd: " . $tijd . "\n\n" . "\n\n" . "Opmerking:" . "\n\n" . $opmerking;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $voornaam . ", we will contact you shortly.";
}
?>
HTML code:
<form action="" method="post">
<table class="tg">
<tr>
<td class="tg-yw4l">Voornaam:</td>
<td class="tg-yw4l">
<input type="text" name="voornaam">
</td>
</tr>
<tr>
<td class="tg-yw4l">Achternaam:*</td>
<td class="tg-yw4l">
<input type="text" name="achternaam" required>
</td>
</tr>
<tr>
<td class="tg-yw4l">Telefoon:</td>
<td class="tg-yw4l">
<input type="text" name="telefoon">
</td>
</tr>
<tr>
<td class="tg-yw4l">E-Mail:*</td>
<td class="tg-yw4l">
<input type="text" name="mail" required>
</td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l">Aantal Personen:*</td>
<td class="tg-yw4l">
<input type="text" name="personen" required>
</td>
</tr>
<tr>
<td class="tg-yw4l">Datum:*</td>
<td class="tg-yw4l">
<input type="date" name="datum" required>
</td>
</tr>
<tr>
<td class="tg-yw4l">Tijd:*</td>
<td class="tg-yw4l">
<input type="time" name="tijd" required>
</td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l">Vraag/Opmerking:</td>
<td class="tg-yw4l">
<textarea rows="10" cols="40" name="opmerking"></textarea>
</td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l">
<input type="submit" name="submit" value="Reserveren">
</td>
</tr>
</table>
</form>
I can't see what I have done wrong here, maybe that my subject, body, and headers are in the wrong places, but other than that I'm not sure really. If anyone could explain what's wrong here I'd be very grateful.