I am trying to make a PHP script which sends mail from a html contact form, the script doesn't throw any error, but it doesn't send mails. The code is below.
mail.php
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = 'stronka@obabie.com'; //<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n" .
"Here is the message:\n $message" .
$to = "bruno.kedzierski@wp.pl";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $email_subject, $email_body, $headers);
header('Location: index.html');
?>
My HTML file:
<div class="container" style="width: 200px; float: left; margin-left: 300px; margin-top: 25px">
<form action="mail.php" method="post">
<div class="form-group" style="margin-left: auto;margin-right: auto;">
<label>Imie i nazwisko</label>
<input type="text" class="form-control" placeholder="Imie i nazwisko " name="name">
</label>
</div>
<div class="form-group" style="margin-left: auto;margin-right: auto;">
<label>E-mail</label>
<input type="email" class="form-control" placeholder="E-mail" name="email" required>
</label>
</div>
<div class="form-group" style="margin-left: auto;margin-right: auto;">
<label>Numer telefonu</label>
<input class="form-control" placeholder="Twoj numer" type="tel">
</label>
</div>
<div class="form-group" style="margin-left: auto;margin-right: auto; width: 400px;">
<label>Wiadomosc</label>
<textarea class="form-control" placeholder="Twoja wiadomosc" style="height: 100px" name="message"> </textarea>
</label>
</div>
<div class="form-group" style="margin-left: auto;margin-right: auto;">
<label>Plec
<select style="form-control">
<option value="chlop">Chlop</option>
<option value="chlop">Baba</option>
<option value="inny">Inna</option>
</select>
</label>
</div>
<div class="radio">
<label style="display: block;">
<input type="radio" name="optradio"> kradne</label>
<label style="display: block;">
<input type="radio" name="optradio"> nie kradne</label>
</div>
<button type="submit" class="btn btn-default" value="submit">Wyslij</button>
</form>
So I added attribute action="mail.php"
and method="post"
, so that the PHP start when I press submit. Can anybody tell why it doesn't work?