http://www.nybn.org/diceform.php
The results do not display nor do any of the emails get sent. Here's the code that's supposed to roll the dice and send the emails. Any help would be appreciated.
<?php // Functions ------------------------------------------
function rollDice($dice) { $faceArray = array();
for ($i=0; $i<$dice; $i++ ) {
$face = rand(1, 10);
$faceArray[$i] = $face; }
return $faceArray; };
function is_valid_email($email) {
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);}
function contains_bad_str($str_to_test) {
$bad_strings = array( "content-type:", "mime-version:", "multipart/mixed", "Content-Transfer-Encoding:", "bcc:", "cc:", "to:" );
foreach($bad_strings as $bad_string) { if(eregi($bad_string, strtolower($str_to_test))) {
echo "$bad_string found. Suspected injection attempt - mail not being sent."; exit; } }}
function contains_newlines($str_to_test) {
if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
echo "newline found in $str_to_test. Suspected injection attempt - mail not being sent."; exit; }}
// Code -------------------------------------------
$name = $_POST['requiredname'];
$dice = $_POST['requireddice'];
$description = $_POST['requireddescription'];
$email = $_POST['requiredemail'];
if (!is_valid_email($email))
{ echo 'Invalid email submitted - mail not being sent.';
exit;}
contains_bad_str($email);contains_bad_str($description);contains_newlines($email);contains_newlines($description);
$faces = rollDice($dice);
for ( $i=0; $i < (count($faces)-1); $i++){
$results = $results . $faces[$i] . ", ";
}
$results = $results . $faces[$i] . ", ";
echo ($results);
function redirect($url)
{
header('Location: http://www.nybn.org/diceform.php ' . $url, true);
die();
}
// email results //
$to = 'dicerolls@nybn.org'.',';
$to .= $email;$subject = "Dice roll for $name";
$message = "$name rolled a $results for $description";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: NYbN Dice Roller <dicerolls@nybn.org>' . "\r\n";
mail ($to, $subject, $message, $headers);
?>