There are two things you have to care about. One is script execution time, which is configurable in php.ini by max_execution_time = (seconds).
The second is, that browser needs to get a response from server from time to time, otherwise it closes the connection. It can be solved by some text echoed to the browser. You have to have some part of script:
while ( $row = mysql_fetch_array()) {
mail(); // to send mail
echo "<SPAN>something</SPAN>";
}
then the browser is getting response and did not stop. You can set is as HTML invisible with STYLE statement, and it would not break your layout.
Zdenek