SMTP Error: Could not connect to SMTP host - теряется соединение в цикле

У меня рассылка оповещений в цикле на каждый имейл. Между каждым циклом таймаут 4 секунды. Периодически вылетает ошибка SMTP Error: Could not connect to SMTP host на каком-то этапе цикла. лог Too many concurrent SMTP connections; please try again later Подскажите, где копать: код, сервер или еще что-то, вообще не пойму в чем проблема ? php 5.6 centos

вот исходник , в цикле запускается так

foreach(){(send_email_s($subject,$message,"",$email,$email_server,$passwd,$server,$name_from)}

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

include_once(realpath(dirname(__FILE__)."/../")."/config/config.php");
include_once (DIR_CMS."/send_subscribe/send_email/Exception.php");
include_once (DIR_CMS."/send_subscribe/send_email/PHPMailer.php");
include_once (DIR_CMS."/send_subscribe/send_email/SMTP.php");




function send_email_s($subject,$message,$name_recipient,$email_recipient,$login,$pass,$server,$name_site)
    {
        $mail = new PHPMailer(true);


    
    try {
        //Server settings
        //$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
        $mail->isSMTP();                                            // Send using SMTP
        $mail->Host       = $server;                    // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = $login;                     // SMTP username
        $mail->Password   = $pass;                               // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
        $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
        
        $mail->SMTPOptions = array(
        'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
        )
        );      
        
        $mail->CharSet    = "UTF-8";
        $mail->Encoding   = 'base64';
        $mail->setFrom($login, $name_site);
        $mail->addAddress($email_recipient, $name_recipient);     // Add a recipient
        
        //$mail->addReplyTo('[email protected]', 'Information');
        //$mail->addCC('[email protected]');
        //$mail->addBCC('[email protected]');

        // Attachments
        //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
        //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body    = $message;
        $mail->AltBody = strip_tags($message);
        $mail->send();
        return true;
    } catch (Exception $e) {
        return $e;
    }
   
    
} 


Ответы (0 шт):