如何设置发送邮件的间隔? [关闭]

when a user submits a form in my website, a notification email will be sent to all active suppliers, which are 250 different suppliers. I used the mail() function for this, but sometimes users see internal server error when trying to submit the form and the emails are repeatedly sent. If different users try to submit the form at the same time, will it cause any problem? Can I set intervals between sending mails if so how? This is my code:

           $emails = mysql_query('select * from supplier_detail where emailquotes = "y" and s_active ="a"');

           while($row = mysql_fetch_assoc($emails)){

            $to = $row['s_email'];
            $headers  = 'MIME-Version: 1.0' . "
";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
    $headers .= 'From: mysitename  <noreply@mysitename.com' . "
";
    mail($to, $subject, $message, $headers);
    }

php mail function accepts multiple email ids. So, you can create a string with all mail ids seperated by commas

$to = array();
while ($row = mysql_fetch_assoc($emails)) {
    $to[] = $row['s_email'];
}
$headers = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$headers .= 'From: mysitename  <noreply@mysitename.com' . "
";
mail(implode(",", $to), $subject, $message, $headers);

Take a look at the sleep() function, your code will look something like this then:

while($row = mysql_fetch_assoc($emails))
{
   $to = $row['s_email'];
   $headers  = 'MIME-Version: 1.0' . "
";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
   $headers .= 'From: mysitename  <noreply@mysitename.com' . "
";
   mail($to, $subject, $message, $headers);
   sleep(1);
}

This will wait for 1 second before continuing.

How about you store a "last_email_sent" value in the database and compare against that? Then you would only send a new email to that person if the time since the last sent is greater than some period of time.