What are the best practices for determining and handling the timeout limit set by the server when sending bulk emails using PHP?

When sending bulk emails using PHP, it is important to handle the timeout limit set by the server to prevent the script from timing out before all emails are sent. One way to handle this is by increasing the timeout limit using the set_time_limit() function in PHP. Additionally, you can check the current timeout limit using ini_get('max_execution_time') and adjust it accordingly.

// Increase the timeout limit to prevent script timeout
set_time_limit(0);

// Check the current timeout limit
$current_limit = ini_get('max_execution_time');
echo "Current timeout limit: " . $current_limit;