Combined Feedback Form
$self = $_SERVER['PHP_SELF'];
$username = $_POST['username'];
$useraddr = $_POST['useraddr'];
$comments = $_POST['comments'];
$sent = $_POST['sent'];
$form ="";
if($sent)
{
$valid=true;
if( !$username )
{ $errmsg.="Enter your name...
"; $valid = false; }
if( !$useraddr )
{ $errmsg .="Enter your email address...
"; $valid = false; }
if( !$comments )
{ $errmsg.="Enter your comments...
"; $valid = false; }
$useraddr = trim($useraddr);
$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}~]+";
$_host = "([-0-9A-Z]+\.)+";
$_tlds = "([0-9A-Z]){2,4}$/i";
if( !preg_match( $_name."@".$_host .$_tlds,$useraddr ) )
{
$errmsg.="Email address has incorrect format!
";
$valid=false;
}
}
if($valid != true)
{
echo( $errmsg.$form );
}
else
{
$to = "php@h.com";
$re = "Feedback from $username";
$msg = $comments;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;";
$headers .= "charset=\"iso-8859-1\"\r\n";
$headers .= "From: $useraddr \r\n";
if(mail($to,$re,$msg, $headers))
{ echo("Your comments have been sent - thanks $username");}
}
?>