Yuki H. 0 Light Poster

I made this php mailform months ago, and I haven't done php in a while, so I need help with it. Though a person might not have a valid email or typed in their name and/or comments it still submits, how can I fix this problem?

<? include('header.txt'); ?>
<table width=408 border=0 cellspacing=0 cellpadding=0 valign="top" align=center>
<div class="welhead">Content</div>

<? echo "Make sure you type in the required fields, those are the ones with the stars next to them.<br>"; ?>
<? if(!$sendme) { ?>

<form action="<? echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data">

<p class="welcome" align="left">*Name:<br />
<input type="text" name="name" size="25" /></p>

<p class="welcome" align="left">*Email:<br />
<input type="text" name="email" size="25" /></p>

<p class="welcome" align="left">Site:<br />
<input type="text" name="site" size="25" value="http://" /></p>

<p class="welcome" align="left">Attachment:<br />
<input type="file" name="attach" size="25" /></p>

<p class="welcome"  align="left">*Comments:<br />
<textarea name="comments" rows="10" cols="35"></textarea></p>

<input type="hidden" name="ip" value="$ip" />

<p align="left"><input type="submit" name="sendme" value="Send!" />&nbsp;&nbsp;<input type="reset" name="reset" value="Oops!" /></p></form>


<?
} elseif ($sendme) { $datetime = date('l, F d, Y H:i:s');
$subject = 'Artbookmanga [dot] net mail';
$comments = stripslashes($comments);
$boundary = md5(time());

if ($attach != '') {
$fp = fopen($attach,'rb');
$attachment = fread($fp,filesize($attach));
$attachment = chunk_split(base64_encode($attachment));
fclose($fp);
}
//start of email validation



    function check_email_mx($email) { 
    	if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) || 
    		(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) { 
    		$host = explode('@', $email);
    		if(checkdnsrr($host[1].'.', 'MX') ) return true;
    		if(checkdnsrr($host[1].'.', 'A') ) return true;
    		if(checkdnsrr($host[1].'.', 'CNAME') ) return true;
    	}
    	return false;
    }

    if (check_email_mx("$email")) {


    } else {

echo "Naughty, Naughty! You thought that you would get away with not typing in a valid email address?<br>";
    }

    if (!function_exists('checkdnsrr')) {
    	function checkdnsrr($host, $type = '') {
    		if(!empty($host)) {
    			if($type == '') $type = "MX";
    			@exec("nslookup -type=$type $host", $output);
    			while(list($k, $line) = each($output)) {
    				if(eregi("^$host", $line)) {
    					return true;
    				}
    			}
    			return false;
    		}
    	}
    }

//end of email validation

if ($name=="" || $comments=="")
{ 
echo "Incomplete submission, please go back and fill in required fields, such as your name and/or comments.<br></td></tr></table>"; include('footer.txt'); exit;}


$headers .= "From: $name<$email>
Reply-To: <$email>
X-Sender: $name<$email>
X-Mailer: Yuki mailer
X-Priority: 3
Return-Path: <$email>
MIME_Version: 1.0
Content-Type: multipart/mixed; boundary=\"MAIN-$boundary\"

This is a multi-part message in MIME format.
--MAIN-$boundary
Content-Type: multipart/alternative; boundary=\"PART-$boundary\"\r\n";$message .= "--PART-$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

mail message on: $datetime

$name
$email
$site

$comments\r\n\r\n";$message .= "--PART-$boundary
Content-Type: text/html; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit\r\n\r\n";

$comments = nl2br($comments);

$ip = $_SERVER['REMOTE_ADDR']; 

$message .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html><head><style type=\"text/css\">
<!--
body { font: 10px Verdana; margin: 0px; color: #000000; background: #9A60EA; text-align: center; }
a:link, a:visited { color: #FFFFFF; text-decoration: none; padding: 2px; }
a:hover, a:active { color: #5145D7; text-decoration: none; background-color: #9A60EA; padding: 2px; }

.content { font-family: verdana; font-size: 12px; color: #FFFFFF; background-color: #9A60EA; border: #0D0656; border-style: solid; border-width: 2px; padding: 5px; width: 80%; text-align: left; }

.head {font-family: verdana; font-size: 12px; color: #FFFFFF; 
background-color: #; border-color: 
#FFFFFF; border-style:solid; border-width: 2px; text-align: center}
-->
</style></head><body bgcolor=\"#BC23E8\" text=\"#000000\">

<div class=\"content\">

<div class=\"head\">$subject Message</div>
<p><b>Received On:</b> $datetime</p>
<p><b>IP address:</b> $ip</p>

<p><b>NAME:</b> $name<br />
<b>MAIL:</b> $email<br />
<b>SITE:</b> <a href=\"$site\">$site</a></p>

<p><b>COMMENTS:</b><br />
$comments</p>

</div></body></html>\r\n\r\n";
$message .= "--PART-$boundary--\r\n\r\n"; 
if ($attach != '') {
$message .= "--MAIN-$boundary
Content-Type: $attach_type; name=\"$attach_name\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$attach_name\"

$attachment\r\n\r\n";

}

$message .= "--MAIN-$boundary--\r\n";

mail("email@address.com",$subject,$message,$headers);

echo "Hi, $name! I would read your mail shortly.<br>";
} ?> 

</td></tr></table>

<? include('footer.txt'); ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.