Blocking vulgar terms from an Email Invite
<p>The code below contains some PHP code that allows users to send out email invites to others.  It works fine.  However, I'm trying to add a function called "check_porn_terms" so that no user could enter their name as "porn" or other vulgar terms and then send an email under that name recommending my site.  The variable "$_POST['sendername']" is the user's name.</p>

<p>The function below does not work.  Any idea how I can get it to work?</p>

<p>Thanks in advance,</p>

<p>John</p>

<pre><code>function check_porn_terms($input) {
    $porn_terms = array("porn", "sex", "etc.");

    return !preg_match('#\b(' . join('|', array_map('preg_quote', $porn_terms)) . ')\b#i', $input);
}


$sendername = $_POST['sendername'];
$sendername = strtolower($sendername);

if(!check_porn_terms($sendername))
{

   session_write_close();
   header("Location:http://www.site.com/friends.htm");
   exit;

}

$msg = "&lt;html&gt;&lt;body&gt;Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use &lt;a href='http://www.site.com/'&gt;Site.com&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;img src='http://site.com/images/blacklogo.PNG'&gt;&lt;/body&gt;&lt;/html&gt;";
$subject = "Try out Site.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}
</code></pre>
