Trying to create a contact form on a website, the code for the form is shown below:
<form name="contact_form" method="POST" action="send_email.php">
<ul id="contact_form">
<li>
<input required type="text" name="name" class="field_style field_split" placeholder="Your Name">
<input required type="email" name="email" class="field_style field_split" placeholder="Your Email">
</li>
<li>
<select required name="subject" class="field_style field_full">
<option value="General Enquiry">General Enquiry</option>
<option value="Coaching Enquiry">Coaching Enquiry</option>
<option value="Other">Other</option>
</select>
</li>
<li>
<textarea required name="message" class="field_style" placeholder="Message"></textarea>
</li>
<li>
<input id="submit_contact" name="submit" type="submit" value="Send Email">
</li>
</ul>
</form>
This form should send an email with the information from the form fields, but it is failing to get the data from the fields when the user presses Submit.
Here is the send_email.php (with the recipient email replaced):
<?php
$to = "name@domain.com";
if(isset($_POST["from"])){ $from = $_POST["from"];}else{echo "from not set.";}
if(isset($_POST["name"])){ $name = $_POST["name"];}else{echo "name not set.";}
if(isset($_POST["subject"])){ $subject = $_POST["subject"];}else{echo "subject not set.";}
if(isset($_POST["message"])){ $message = $_POST["message"];}else{echo "message not set.";}
if(mail($to, $subject, $message))
{
header("Location: #");
}else{
echo "Error: ";
print_r(error_get_last());
}
?>
And it returns the following message:
from not set.
name not set.
subject not set.
message not set.
Error: Array ( [type] => 8 [message] => Undefined variable: message [file] => /home/u884620714/public_html/send_email.php [line] => 14 )
Anyone have any ideas, because I'm new to PHP and don't understand why the data is not fetched from the form.
Thanks for the help in advance.