I got this working with code:
$filename="123.txt";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
$ex = preg_split('/\s+/', $contents);
foreach ($ex as $user) {
echo "$user";
mysql_query("INSERT INTO newusers SELECT * FROM oldusers WHERE email='{$user}'");
}
fclose($handle);
Problem was that after reading text file line by line I was getting a space after every email so output was like:
some@thing.com any@thing.com goo@gle.net etc.
And because of this space after every email SQL though emails were different. But with calling preg_split() I removed spaces and everything is working. I hope I wrote it understandable.