I think THIS is what you are after, or something like it??:
<?php
$form = '<form action="test.php" method="post">
<p><input type="text" name="email" size="25" /> Email</p>
<p><textarea name="body" rows="10" cols="50"></textarea> Body</p>
<input type="submit" name="submit" value="Send" />
</form>' . "\n";
// if the form was submitted:
if(isset($_POST['email']) && isset($_POST['body']))
{
// hide form:
$displayForm = false;
// if magic quotes, srip slashes:
if(get_magic_quotes_gpc() == 1)
{
$email = stripslashes($_POST['email']);
$body = stripslashes($_POST['body']);
}
else {
$email = $_POST['email'];
$body = $_POST['body'];
}
// validate e-mail address
if(!eregi('^([0-9a-z]+[-._+&])*[0-9a-z]+@([-0-9a-z]+[.])+[a-z]{2,6}$',$email))
{
echo 'Your email address appears to be invalid';
$displayForm = true;
echo $form;
}
// validate body:
elseif(eregi("(to:)|(from:)|(cc:)|(bcc:)",$body))
{
echo 'Hack attempt?';
$displayForm = true;
echo $form;
}
else {
// email
$to = 'name@domain.com';
$headers = 'From: name@domain.com' . "\r\n";
$messageSubject = 'PHP Feedback Form Test';
$confirmationSubject = 'Your email was sent';
$confirmationBody = "Well done!!!!";
$send = @mail($to,$messageSubject,$body,'From: '.$email."\r\n");
$send2 = @mail($email,$confirmationSubject,$confirmationBody.$body, $headers);
echo 'Thanks. Your message was sent';
}
}
// else display form:
else {
$displayForm = true;
echo $form;
}
?>
That being said, I am not certain that checking the BODY for those characters will prevent spam or do what you wish it to do.
My thinking is based on the idea that TO:,BCC:, CC:, settings must be established as an email parameter, usually the headers. If you use those in the "body" or message of the email, it will NOT affect the recipients of the email.
Anyway, I hope that helps...