I'm having endless troubles creating a contact form in PHP.
I first tried the method to write the data (as outlined in the question here: HTML Form Not Outputting To CSV File (Or Displaying Correct Error Messages)) and now I'm just trying the method of sending the info in an e-mail to myself.
Here's my jsfiddle:
Here's the PHP I've written to send the info to myself (I understand it's not very elegant coding but I just want to get something to work first and then I was going to use arrays, etc.):
<?php
if (isset($_POST['brandname']) && isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email']) && isset($_POST['website'])){
$brandname = $_POST['brandname'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$website = $_POST['website'];
if(!empty($brandname) && !empty($firstname) && !empty($lastname) && !empty($email)){
$to = 'myemail@example.com';
$subject = 'Submission Form';
$body = $firstname;
$headers = 'From: '.$email;
if (@mail($to, $subject, $body, $headers)){
echo 'Yeah yeah';
}else{
echo 'yeah no.';
}
}else{
echo 'Please fill out all required fields.';
}
}
?>
The e-mail I used in this example is obviously not my e-mail (I use my real one in my code). Basically what happens is I fill out the form and hit submit and it reloads the form.php page. I check my e-mail and nothing has come through. If I check the source code for the site the words 'Yeah yeah.' show up in the code (from where it echos out when it successfully sends the e-mail). So the code seems to be running properly but it's not outputting anything.
Do I have to set up some mail servers/functions through my localhost?
What am I missing out on?