0

The script was written by someone else and I'm a novice at best when it comes to php. I know it worked before, but now after switching to a new server and upgrading to php7, I get no output from the roller. No emails, no nothing. Please tell me there's someone out thre that can tell me what's wrong and possibly how to fix it!

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Dice Handler</title>

    </head>


    <body>


<?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 = "From: " . $from . "\r\n" . "Reply-To: " . $from . "\r\n" . "X-Mailer: PHP/" . phpversion();
    $headers .= 'From: NYbN Dice Roller <dicerolls@nybn.org>' . "\r\n";

    mail($to, $subject, $message, $headers);
?>
    </body>
    </html>
GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71
Beanman1
  • 1
  • 2

0 Answers0