I want my contact form to send me an email once filled out and the user hits submit. So far, the page will take me to the "Your message has been sent!" page (confirmation.htm), yet I never receive an email. I place my email in the section that says
$to = "myEmail@mail.com";
I've checked my spam folder as well, it doesn't go there either.
Here's my contact form (HTML):
<div class="span">
<form action="mailer.php" method="post" class="comments-form contact-form">
<input type="text" name="name" placeholder="Your Name*" class="name" />
<input type="text" name="email" class="email" placeholder="Your Email*" />
<select>
<option value="Subject">Subject</option>
<option value="content-writing">Content Writing</option>
<option value="other">Other</option>
</select>
<textarea class="message" type="text" name="comment" placeholder="Your Message*"></textarea>
<input name="submit" type="submit" class="submit-comment" value="Send Message" />
</form>
</div>
Then here's my php:
<?php
if(isset($_POST['submit'])) {
$to = "myEmail@mail.com";
$subject = "Message from your Portfolio!";
// data the visitor provided
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
//constructing the message
$body = " From: $name_field\n\n E-Mail: $email_field\n\n Message:\n\n $comment";
// sending the message
mail($to, $subject, $body);
// redirect to confirmation
header('Location: /confirmation.htm');
} else {
echo "Something went wrong :(";
}
?>