As I am newbie to PHP any help will be appreciated. I have made a lot of changes trying to fix it but nothing seems to work. When I submit the form nothing happens but after typing mail.php in url , the blank email is being sent and error occurs.
I have tried using if($_POST) or if(isset($_POST['submit-btn'])) etc. but nothing changed and still i can't access input values.
I'm receiving an error of undefined index as below:
submit not exist
Notice: Undefined index: contact-name in */mail.php on line 11
Notice: Undefined index: contact-mail in */mail.php on line 12
Notice: Undefined index: contact-subject in */mail.php on line 14
Notice: Undefined index: contact-msg in */mail.php on line 15
The email message was sent.
HTML form:
<form action="mail.php" method="POST">
<input type="text" name="contact-name" required>
<input type="text" name="contact-mail" required>
<input type="text" name="contact-subject" required>
<textarea name="contact-msg" required></textarea>
<div class="contact__policy">
<p><input type="checkbox" class="checkbox" required> I have read and accept <a href="*/policy link/*">Privacy Policy</a>.</p>
<button class="submit-btn" type="submit" name="submit-btn">Send</button>
</div>
</form>
Current PHP
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
if(isset($_POST['submit-btn'])) {
echo "submit exist";
} else {
echo "submit not exist";
}
$name = $_POST['contact-name'];
$from = $_POST['contact-mail'];
$to = "kilm1@o2.pl";
$subject = $_POST['contact-subject'];
$message = $_POST['contact-msg'];
$txt = "Name: " . $name . "\n" . "E-mail: " . $from . "\n\n" . "Message: " . $subject . "\n\n" . "Content: " . $message;
$headers = "From:" . $from;
mail($to, $subject, $txt, $headers);
if(mail($to,$subject,$txt, $headers)) {
echo "The email message was sent.";
} else {
echo "The email message was not sent.";
}
?>