I know that there is a ton of solutions to this problem but i need to validate email in a contact form.
this is my php mailer so far:
<?php
if (isset($_POST['send'])){
$to = "mail@mail.something";
$subject = "new message";
$firstname = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{echo "<script>alert('thanks for the message:) ');</script>";
}else
{echo "<script>alert('sorry, message wasn't send');</script>"; }
}
?>
I have tried with filter_var
$result = filter_var( 'something@something.something', FILTER_VALIDATE_EMAIL );
but, doesn't work.
If my way to sent mail through contact form isn't the "best practice way" feel free to correct me and send me on the right path :D