Everything seems to working properly, and I'm not getting any errors on front end or from the network.
However, when I test the code I am not receiving an email to the $to account.
Question
How can I alter the code below so an email is sent and received.
Here is my code.
<?php
$to = 'test@test.com'; // Change your email address
$name = $_POST['name'];
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($email) && isset($name) && isset($subject) && isset($message) &&
filter_var($email, FILTER_VALIDATE_EMAIL) ) {
// detect & prevent header injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if ( preg_match( $test, $val ) ) {
exit;
}
}
$body = <<<EMAIL
subject : $subject
My name is, $name.
$message
From : $name
Email : $email
EMAIL;
$header = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>' . "\r\n" .
'Reply-To: ' . $_POST["email"] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// mail( $to , $_POST['subject'], $_POST['message'], $headers );
mail($to, $subject, $body, $header);
}
?>
I think it's something small as i'm not getting any real errors and nothing is blowing up. This is some of my first times working in PHP, so perhaps I'm missing something bigger.