Ok I've got the basic form. On Post it sends the user to a .php file which checks to see if all the forms have been filled out. If not it echos the missing fields. Once the the user has inserted something in all the fields it will continue with the process and send the mail.

Now want I am wanting to do is Validate the E-mail addess typed into the field. I know how to Validate the E-mail, but not really add it into this current script. So I'm going to list all my code and see if someone can help me implement them all together, cool?

Ok here is the Form code.

<form class="forms" name="form" method="post" action="Thanks.php">
<p class="bodymd">Your Name<br>
<input class="forms" type="text" name="Name">
</p>
<p class="bodymd">Your Email<br>
<input class="forms" type="text" name="Email">
</p>
<p class="bodymd">Comments or Questions<br>
<textarea name="Comments" class="forms" rows="5"></text>
</p>
<p class="bodymd">
<input class="button" type="submit" name="Submit" value="Submit">
<input class="button" type="reset" name="Reset" value="Clear Form">
</p>
</form>

After they enter the fields they are sent to a .php file with this.

<?php

if (($Name == "") || ($Email == "") || ($Comments == ""))
{
	echo "<form name=form method=post class=forms action=Thanks.php>";
	echo "<p class=bodymd>All three fields of this form are required.</p>";
	echo "<p class=bodymd>Fill in the ones you missed, they are listed below.</p>";
}
if ($Name == "")
{
	echo "<p class=bodymd>Your Name<br><input class=forms type=text name=Name></p>";
}
else
{
	echo "<input class=forms type=hidden name=Name value=$Name>";
}
if ($Email == "")
{
	echo "<p class=bodymd>Your Email<br><input class=forms type=text name=Email></p>";
}
else
{
	echo "<input class=forms type=hidden name=Email value=$Email>";
}
if ($Comments == "")
{
	echo "<p class=bodymd>Comments or Questions<br><textarea name=Comments rows=5 cols=40 class=forms></text></p>";
}
else
{
	echo "<input class=forms type=hidden name=Comments value=$Comments>";
}

if (($Name == "") || ($Email == "") || ($Comments == ""))
{
	echo "<input class=button type=submit name=Submit value=Submit>";
	echo "<input class=button type=reset name=Reset value=Clear Form>";
	echo "</form>";
}
else
{
	$message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
	$extra = "From: $Name\r\nReply-To: $Email\r\n";
	mail ("Kriek@jonkriek.com", "Website Email", $message, $extra);
	echo "<p class=bodymd>Thanks for your inguiry, $Name.</p>";
	echo "<p class=bodymd>A response will be sent to $Email as soon as possible.</p>";
}
?>

Now here is what I am trying to hook up to Validate the e-mail.

<?php function validate_email ($email) { 

# Trim out 'null' characters 
$email = ereg_replace("\t","",$email); 
$email = ereg_replace("\r","",$email); 
$email = ereg_replace("\n","",$email); 
$email = ereg_replace(" ","",$email); 

# Email addresses are not case sensitive 
$email = strtolower($email); 

# Must contain '@' and '.' 
if ((!ereg("@",$email)) || (!ereg(".",$email))) { 
return "1"; 
} 
# Must be at least 7 characters long (x@y.com) 
elseif (strlen($email) < 7) { 
return "2"; 
} 
else { 

# Split on the @ sign 
$parts = split("@", $email, 2); 

# First part is user 
$user = $parts[0]; 

# Second part is domain 
$domain = $parts[1]; 

# Domain must contain at least 1 dot. 
if (!ereg("\\.",$domain)) { 
return "3"; 
} 
# Must be a least 4 characters (z.com) 
elseif (strlen($domain) < 4) { 
return "4"; 
} 
# May not start with a dot 
elseif (ereg("^\\.",$domain)) { 
return "5"; 
} 
# May not have more than one dot in sequence 
elseif (ereg("\\.\\.",$domain)) { 
return "6"; 
} 
else { 

# User must be at least 1 character long 
if (strlen($user) < 1) { 
return "7"; 
} 
# User cannot contain a comma 
elseif (ereg("\\,", $user)) { 
return "8"; 
} 
else { 

# Split on the . character 
$parts = split("\\.", $domain); 

# There must be at least two parts to a domain (a sub domain would have 3 - a.b.com) 
if (count($parts) < 2) { 
return "9"; 
} 
else { 

# First part is domain name 
$name_at = count($parts) - 2; 
$name = $parts[$name_at]; 

# Second part is domain extention 
$ext_at = count($parts) - 1; 
$ext = $parts[$ext_at]; 

$first_name = substr($name, 0, 1); 

# Name must be at least one character 
if (strlen($name) < 1) { 
return "10"; 
} 
# Name cannot be more than 26 characters 
if (strlen($name) > 26) { 
return "11"; 
} 
# Extention must be 2 or 3 characters (.nu - .com) 
elseif ((strlen($ext) > 3) || (strlen($ext) < 2)) { 
return "12"; 
} 
# Domain can only contain the following characters 
elseif (strspn($name, "abcdefghijklmnopqrstuvwxyz0123456789-.") != strlen($name)) { 
return "13"; 
} 
# Domain can only start with the following characters 
elseif (strspn($first_name, "abcdefghijklmnopqrstuvwxyz") < 1) { 
return "14"; 
} 
# Extension can only contain the follow characters 
elseif (strspn($ext, "abcdefghijklmnopqrstuvwxyz") != strlen($ext)) { 
return "15"; 
} 
else { 

return $email; 

} 

} 

} 

} 

} 

} ?>

Not even sure it will work.
Any help would be great.

    This shuold do what you need.

    Instead of checking for a blank email, check for a valid email (an blank email is invalid after all).

    =====================================
    <?php

    if (($Name == "") || ($Email == "") || ($Comments == ""))
    {
    echo "<form name=form method=post class=forms action=Thanks.php>";
    echo "<p class=bodymd>All three fields of this form are required.</p>";
    echo "<p class=bodymd>Fill in the ones you missed, they are listed below.</p>";
    }
    if ($Name == "")
    {
    echo "<p class=bodymd>Your Name<br><input class=forms type=text name=Name></p>";
    }
    else
    {
    echo "<input class=forms type=hidden name=Name value=$Name>";
    }

    $valid_email = eregi("[a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $Email);
    if (!$valid_email)
    {
    echo "<p class=bodymd>Your Email<br><input class=forms type=text name=Email></p>";
    }
    else
    {
    echo "<input class=forms type=hidden name=Email value=$Email>";
    }
    if ($Comments == "")
    {
    echo "<p class=bodymd>Comments or Questions<br><textarea name=Comments rows=5 cols=40 class=forms></text></p>";
    }
    else
    {
    echo "<input class=forms type=hidden name=Comments value=$Comments>";
    }

    if (($Name == "") || ($Email == "") || ($Comments == ""))
    {
    echo "<input class=button type=submit name=Submit value=Submit>";
    echo "<input class=button type=reset name=Reset value=Clear Form>";
    echo "</form>";
    }
    else
    {
    $message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
    $extra = "From: $Name\r\nReply-To: $Email\r\n";
    mail ("Kriek@jonkriek.com", "Website Email", $message, $extra);
    echo "<p class=bodymd>Thanks for your inguiry, $Name.</p>";
    echo "<p class=bodymd>A response will be sent to $Email as soon as possible.</p>";
    }
    ?>

    if ($Email == "")
    {
    echo "<p class=bodymd>Your Email<br><input class=forms type=text name=Email></p>";
    }
    else
    {
    echo "<input class=forms type=hidden name=Email value=$Email>";
    }
    if ($Comments == "")
    {
    echo "<p class=bodymd>Comments or Questions<br><textarea name=Comments rows=5 cols=40 class=forms></text></p>";
    }
    else
    {
    echo "<input class=forms type=hidden name=Comments value=$Comments>";
    }

    if (($Name == "") || ($Email == "") || ($Comments == ""))
    {
    echo "<input class=button type=submit name=Submit value=Submit>";
    echo "<input class=button type=reset name=Reset value=Clear Form>";
    echo "</form>";
    }
    else
    {
    $message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
    $extra = "From: $Name\r\nReply-To: $Email\r\n";
    mail ("Kriek@jonkriek.com", "Website Email", $message, $extra);
    echo "<p class=bodymd>Thanks for your inguiry, $Name.</p>";
    echo "<p class=bodymd>A response will be sent to $Email as soon as possible.</p>";
    }
    ?>

      That looks like it should work, but it doesnt work either way I do it. Even the old function doesnt.

      Not sure if I'm allowed to post links
      but check out what it's doing here ...

      http://www.jonkriek.com/testa.php

        Write a Reply...