Page 1 of 1

Hi Im a noob can u help with my form email validation?

Posted: Tue Mar 16, 2010 11:47 am
by skooby
Im not php coder but i have put to gether a form validation script but it needs to validate email, it just check that an input has been put in, can you help me.

here the script:

<?php
if ($_POST['submit'])
{
$to = "my email here <contact_from@my email here>";
$subject = "my subject here ".strftime("%T", time());



$name_first = $_POST['name_first'];
$name_second = $_POST['name_second'];
$name_business = $_POST['name_business'];
$phone_business = $_POST['phone_business'];
$email = $_POST['email'];
$message = $_POST['message'];

$errorstring = "";


if (!$name_first)
$errorstring = $errorstring."First Name<br>";

if (!$name_second)
$errorstring = $errorstring."Second Name<br>";

if (!$name_business)
$errorstring = $errorstring."Business Name<br>";


if (!$email)
$errorstring = $errorstring."Email<br>";


if (!$message)
$errorstring = $errorstring."Message<br>";

if ($errorstring!="")
echo "Please fill in the following field(s):<br><p>$errorstring<p>";

else
{
$message_sent = "

<html>


<body>
<p style=color:#f00;>From:</p>
<p style=color:#333;>$name_first &nbsp; $name_second</p></br>
<p style=color:#f00;>Email Address:</p>
<p style=color:#333;>$email</p></br>
<p style=color:#f00;>Business Name:</p>
<p style=color:#333;>$name_business</p></br>
<p style=color:#f00;>Phone Number:<p>
<p style=color:#333;>$phone_business</p></br>
<p style=color:#f00;>Message:</p>
<p style=color:#333;>$message</p>


</body>
</html>";



$message_sent = wordwrap($message_sent,70);


$headers = "From: {$email}\n";
$headers .= "Reply-To: {$email}\n";
$headers .= "MIME-Version: 1.0' \n";
$headers .= "Content-Type: text/html; charset=iso-8859-1";






mail($to, $subject, $message_sent, $headers);

$redirect = 'my confermation page here.php';
echo '<html><head><META HTTP-EQUIV=REFRESH CONTENT="0; URL='.$redirect.'"></head></html>';
die ;
}


}

?>


thanks for any feed back

Skooby

Re: Hi Im a noob can u help with my form email validation?

Posted: Tue Mar 16, 2010 1:20 pm
by AbraCadaver

Code: Select all

filter_var($email, FILTER_VALIDATE_EMAIL);

Re: Hi Im a noob can u help with my form email validation?

Posted: Tue Mar 16, 2010 2:09 pm
by skooby
thanks AbraCadaver that works great.

Any function or code snipit to see if the domain is valid or checking the mx record or some such thing.

BTW what did you think of the script, as I said not a php coder just hacked together from different tutorials.

Skooby