Bulk UnBlacklist emails

I threw this together to try and help you un-blacklist many at once.
STEP 1
Create a plain text file called unblacklist.txt.
Add all of the email addys to that file (one per row).
These are the addys that will be removed from the blacklist.

STEP 2
Copy the following code to a new file and save it as unblacklist.php.
Edit lines 2-6 to have the same values as your PHPList config file.

STEP 3
Upload both files to your site and visit http://yoursite.com/unblacklist.php

<?php
$database_host = "myhost";                /* AVAILABLE IN YOUR CONFIG FILE */
$database_user = "myuser";                /* AVAILABLE IN YOUR CONFIG FILE */
$database_password = "mypassword";        /* AVAILABLE IN YOUR CONFIG FILE */
$database_name = "myDBname";            /* AVAILABLE IN YOUR CONFIG FILE */
$table_prefix = "phplist_";                /* AVAILABLE IN YOUR CONFIG FILE */
$conn = mysqli_connect($database_host, $database_user, $database_password, $database_name);
$good1 = $good2 = $good3 = 0;
$bad1 = $bad2 = $bad3 = 0;
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$file = fopen("unblacklist.txt","r"); // Input file.
    while(!feof($file)) {
        $myline=fgets($file);
        $myline=rtrim($myline);
        $sql = "SELECT id FROM ".$table_prefix."user_user WHERE email = '".$myline."';";
        if (mysqli_query($conn, $sql)) {
            $result = mysqli_query($conn, $sql);
            $row = mysqli_fetch_array($result);
            $uid = $row['id'];
        } else {
            echo "Could not get userid for: ".$myline." : " . mysqli_error($conn)."<br />";
        };
        $sql = "UPDATE ".$table_prefix."user_user SET ".$table_prefix."user_user.blacklisted = 0 WHERE email = '".$myline."';";
        if (mysqli_query($conn, $sql)) {
            echo "$myline<br />";
            $good1++;
        } else {
            echo "$myline &nbsp; &nbsp; user_user.blacklisted = Error: " . mysqli_error($conn);
            $bad1++;
        };
        $sql = "DELETE FROM ".$table_prefix."user_blacklist WHERE email = '".$myline."';";
        if (mysqli_query($conn, $sql)) {
            $good2++;
        } else {
            echo " &nbsp; &nbsp; user_blacklist deletion = Error: " . mysqli_error($conn);
            $bad2++;
        };
        $sql = "DELETE FROM ".$table_prefix."user_blacklist_data WHERE email = '".$myline."';";
        if (mysqli_query($conn, $sql)) {
            $good3++;
        } else {
            echo " &nbsp; &nbsp; user_blacklist_data deletion = Error: " . mysqli_error($conn) ."<br />";
            $bad3++;
        };
        $sql = "DELETE FROM ".$table_prefix."user_user_history WHERE userid = '".$uid."' AND summary LIKE 'Added to blacklist%';";
        if (mysqli_query($conn, $sql)) {
            $good3++;
            echo "SUCCESS";
        } else {
            echo " &nbsp; &nbsp; user_user_history deletion = Error: " . mysqli_error($conn) ."<br />";
            $bad3++;
        };
    };
fclose($file);
mysqli_close($conn);
echo "$good1 user_user.blacklist set to 0 &nbsp; &nbsp; $bad1 failed<br />$good2 user_blacklist rows deleted &nbsp; &nbsp; $bad2 failed<br />$good3 user_blacklist_data rows deleted &nbsp; &nbsp; $bad3 failed";
?>

This should do what you want, but PLEASE backup your database before you do this.

1 Like