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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skooby
Forum Newbie
Posts: 2
Joined: Tue Mar 16, 2010 11:41 am

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

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post by AbraCadaver »

Code: Select all

filter_var($email, FILTER_VALIDATE_EMAIL);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
skooby
Forum Newbie
Posts: 2
Joined: Tue Mar 16, 2010 11:41 am

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

Post 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
Post Reply