wp_mail sending only once inside foreach loop

Sometimes the mail port can get clogged up, so I usually add a brief sleep(10) in the for-loop. The 10 seconds is arbitrary, but it works for my purposes.

foreach($entries as $key=>$entry){

    $email = array( '[email protected]' );
    $subject = "Documents Requested";
    $headers = array('Content-Type: text/html; charset=UTF-8');

    $message = getDMVemailMessage($entries[$key]['id']);

    $sent = sendDMVNotifyEmail($email, $subject, $message, $headers);

    sleep(10); //Delay for 10 seconds
}

Alternatively, I’ve also used WP-Cron to process in groups of X at a time, especially if you have hundreds, the sleep() function may cause you to time out. Let me know if you’d like that example code too.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)