bradgrafelman wrote:start from scratch, rather than try to fix the numerous errors you have now.
Here are a couple more:
while (!!in_array($sp_hostname,$sp_site)) {
First, The "!!" is doubly redundant: it's a double-negative and would turn anything considered "false" into false and anything else into true. But (a) in_array returns true or false[/b] already, so the double negative has no effect on the result; and even if it did, (b) the while statement would have converted the result to true or false itself if it needed to.
But there is an even more serious issue in that line: either $sp_hostname is in the $sp_site array or it isn't. If it isn't, the email is skipped. If it is, then the email will be generated and sent and the loop will repeat. $sp_hostname hasn't been removed from the array, so the in_array test will succeed again, an email will be generated and sent, and the loop will repeat....
Almost certainly that while should be an if.