Sending emails in bulk - PHPMailer

Good Morning!

I own an email marketing system and am having trouble performing a newsletter trigger for a large list of contacts. (Understand large list as: a list containing over 1000 emails).

If I perform the trigger for an amount less than 1000 emails, the trigger happens perfectly. If there are more than 1000, it does not send to all, even sending to only half of the list.

Contact Localweb, server that hosts My Accounts and where I authenticate SMTP, and they informed me that it could be a possible loss of packets during sending.

My Code searches the database (SQL Server) within a loop for all the emails from the list that was selected for firing and then sends them. One consideration: submission is performed by a Cron Job that runs every 5 minutes.

Can anyone help me? Any idea what it might be?

My Code shipping:

    $mail = new PHPMailer();
    $mail->setLanguage('br');
    $mail->CharSet='utf-8';   
    $mail->IsSMTP(); 
    $mail->Host = "xxx";
    $mail->SMTPAuth = true;
    $mail->Username = 'xxx';
    $mail->Password = 'xxx';
    $mail->SMTPSecure = 'tls'; 
    $mail->Port = 587; 
    $mail->From = $email; (variável que vem do banco de dados)
    $mail->FromName = $fantasia; (variável que vem do banco de dados)
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    for($z=0; $z<count($bcc); $z++){

        if($html == '1'){
            $topo = recebe um código html específico;
              $rodape = recebe um código html específico;
              $texto2 = recebe um código html específico, concatenando as variáveis $topo e $rodape - newsletter que será enviada; 
        }else{
            if($topo == '1'){
              $topo = recebe um código html específico;
              $rodape = recebe um código html específico;
            }else{
                $topo = recebe um código html específico;
              $rodape = recebe um código html específico;
            }

            $texto2 = recebe o código html específico, concatenando $topo e $rodape - newsletter que será enviada; 
        }

        $mail->AddAddress($bcc[$z]['Email']);
        $mail->IsHTML(true);
        $mail->Subject  = $tit; (variável vinda do banco)
        $mail->Body = $texto2;
        $mail->AltBody = $texto2;
        $enviado = $mail->Send();
        $mail->ClearAllRecipients();
        $mail->ClearAttachments();

    }
Author: Raabe Sampaio, 2017-10-24

2 answers

The script may be finishing the process before the time, try using the command:

set_time_limit(0);

Documentation: http://php.net/manual/pt_BR/function.set-time-limit.php

It sets the time that the script will run, when you set the time to 0, this time is unlimited.

It can be finished also by consuming a lot of processing, try to put a time between 100 and 100 e-mail for example using sleep.

sleep(10);

This time is in seconds

 0
Author: Wictor Chaves, 2017-10-24 15:20:28

I believe it is a limitation of the hosting itself. Usually a third party service is used for this type of sending, such as: mailgun, mailchimp among others. They have a very easy to integrate API and have free plans.

Hope I helped.

 1
Author: Eduardo Abreu dos Santos, 2017-10-24 14:47:51