Bulk mailing - Phpmailer

Asked

Viewed 1,548 times

-1

Good morning!

I have an email marketing system and I am having problems when performing a newsletter shot to a large contact list. (Understand large list as: a list containing over 1000 emails).

If I fire the shot for less than 1000 emails, the shot goes off perfectly. If there are more than 1000, it does not send to everyone, getting to send up to only half of the list.

I contacted Localweb, the server that hosts my accounts and where I authenticate SMTP, and they informed me that it may be a possible packet loss while sending.

My code searches the database (SQL Server) within a loop for all the emails from the list that was selected for shooting and then sends. One consideration: sending is done by a Cron Job that runs every 5 minutes.

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

My shipping code:

    $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();

    }

3 answers

0

I believe it is a limitation of the hosting itself. A third party service is usually used for this type of shipment, such as: Mailgun, Mailchimp and others. They have a very easy-to-integrate API and have free plans.

I hope I’ve helped.

  • Do you know anything about this "packet loss" or if Phpmailer has a limit? Because it just skips a few emails and sends them to others.

  • Does he return any mistakes? Here is a link from the Phpmailer github about sending to lists: https://github.com/PHPMailer/PHPMailer/wiki/Sending-to-lists

  • No... No error :( It simply does not send... And as I said up there, if I have a list for 9,000 contacts, sometimes it can go as high as 4,000. I saw about this doc of Phpmailer and I follow these instructions for optimization, but I do not know what can be happening :(

  • A doubt, it’s skipping shipping or to at a certain time?

  • He skips shipments, some he shoots like that jumping and other points on the list, 50/100 emails in a row, he doesn’t even shoot anymore. It makes sense?

-1


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

set_time_limit(0);

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

It sets the time 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

  • But... For example: I have a list with 9000 contacts and my script shoots to only 7000... Only that there is an order, it does not follow the order that comes from the bank, it "picks" some emails and sends. Does it make sense? And the use of ini_set('max_execution_time', time) is a good?

  • You can make something simpler, as for example in multiples of 100 it makes the waiting if (0 == ($z % 100)){ Sleep(10) ; }

-2

Surely your 5min CRON is not enough to send all these emails. Since Phpmailer is like a Curl. For each upload it establishes a connection to the server, authenticating and processing one at a time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.