is there a way to validate an email in this form without rewriting it completely? It'd be great if I could just add something to this. I'm new to PHP and this form is taken from mmtuts video. If you know how to help, I'd be glad if you did.
<?php if (isset($_POST['submit'])) { $name = $_POST['name']; $number = $_POST['number']; $subject = $_POST['subject']; $mailFrom = $_POST['mail']; $message = $_POST['message']; $mailTo = "[email protected]"; $headers = "From: ".$mailFrom; $txt = "Pan/í ".$name." vám poslal/a zprávu. Telefonní číslo: ".$number."\n\n".$message; mail($mailTo, $subject, $txt, $headers); header("Location: index.php?mailsend"); }
<input />type fromtexttoemailand just letting the frontend deal with it (not recommended). On the server you can use PHP'sfilter_var()function withFILTER_VALIDATE_EMAIL(example) to test the format of the string, and/or do an MX lookup to ensure the domain has a valid mail exchange. Beyond that, you'd have to send the email.