First, tabs are good:
<?php
for($x=1;$x<=600;$x++){
$con = mysqli_connect("host","database","password");
if (!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"database");
$sql="SELECT email FROM emails Where id = ".$x;
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$to = $row['email'];
if ($to == "NULL"){
}else{
echo $row['email'];
mysqli_close($con);
// mail($to,"subject","message");
sleep(2);
}
}
?>
Next, you're telling your script to make the query 600 times. I would suggest instead that you make a single query and then loop through the results, for 599 less queries.
<?php
$con = mysqli_connect("host","database","password");
if (!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"database");
// Set Limit of 600 in the query if for some reason you have more records but only
// want to send that many mails. Otherwise it will run until it goes through all records found.
$sql="SELECT email FROM emails";
$result = mysqli_query($con,$sql);
$num=mysqli_num_rows($result);
if($num != 0){
while ($row = mysqli_fetch_assoc ($result)) {
$to = $row['email'];
if ($to == "NULL"){
}else{
echo $row['email'];
// mail($to,"subject","message");
sleep(2);
}
}
}
mysqli_close($con);
?>
Cutting out that many db connections may resolve your issue. If not, I'd suspect your host is limiting the php mail function. If that's the case, altering the script to use SMTP may be the way to go.