I am setting up a small webpage for a project and I had issues getting the inputs from the contact form to be sent to my email address. The code runs just fine, not prompting any errors but I am not receiving the email that the customer fills up on the contact form.
Could anyone advise? I am currently hosting it for free using infinityfree so does it affect the mail() function? Below is the .php code file I used for my backend.
<?php
$to = 'myemail@gmail.com';
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);
$from = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$subject = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_SPECIAL_CHARS);
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_SPECIAL_CHARS);
if (filter_var($from, FILTER_VALIDATE_EMAIL)) {
$headers = ['From' => ($name?"<$name> ":'').$from,
'X-Mailer' => 'PHP/' . phpversion()
];
mail($to, $subject, $message."\r\n\r\nfrom: ".$_SERVER['REMOTE_ADDR'], $headers);
die('OK');
} else {
die('Invalid address');
}
?>