If by 'table' you mean a database table, you'll need to run a query to fetch each email and its associated random id. not sure why you put the random ids in a separate table.
This code assumes you are using MySQL as your database technology. This may not be the case. I'm also guessing what your database fields are. That said, this code will probably not work for you but it should show a possible approach.
// YOU WOULD NEED TO PUT CODE TO CONNECT TO YOUR DB HERE
// this is an SQL query to fetch your emails with their associated random IDs
$sql = "select u.email, a.randomID from users u, activekeys a WHERE a.userid=u.id";
// this runs the query
$result = mysql_query($sql)
or die('query failed');
while($row = mysql_fetch_assoc($result)) {
$email = $row['email'];
$randomID = $row['randomID'];
$activate_url = 'http://yourdomain.com/activate.php?id=' . $randomID;
$mail_message = "To activate your account, please click this link:\n" . $activate_url
mail($email, 'Important Account Message from yourdomain.com', $mail_message)
or die('mail failed');
}
Then you need a page, activate.php which does the re-activating or whatever.