質問

Ok so basically I need to send 38,400 email from a regular hosting using HostGator. I'm currently using PHPMailer which works fine. What I do, is that the client simply fills an E-mail Template and I save all the E-mail content just so it's easier for me to handle the E-mail content.

When the client wants to send the E-mail I asynchronously call a php code to send the e-mails.

            $.ajaxSetup({cache: false});
            $.ajax({
                async:true,
                type: "POST",
                dataType: "html",
                contentType: "application/x-www-form-urlencoded",
                url:"operaciones.php",
                data:"idcorreo1="+idCorreo+"&operaciones=enviarPlantilla4",
                success:function(data){
                    console.log(data);
            },
                cache:false
            });

That is my AJAX code which basically calls the php process. Now my php code which is the called code:

                 if(isset($_REQUEST["idcorreo1"])){
                        $boletin = new Boletin();
                        $boletinesActivos = array();
                        $numBoletinesActivos = $boletin  -> contarBoletinesActivos();


                        $progresoMailing = new ProgresoMailing();
                        $idCorreo = $_REQUEST["idcorreo1"];
                        $tipoCorreo = 1;//correo1, tmpcorreo1;
                        $fechaYHoraInicio = date("Y-m-d h:i:sa");

                        $progresoMailing -> idCorreo = $idCorreo;
                        $progresoMailing -> tipoCorreo = $tipoCorreo;
                        $progresoMailing -> fechaYHoraInicio = $fechaYHoraInicio;
                        $progresoMailing -> numCorreos = $numBoletinesActivos;

                        $progresoMailing -> insertarProgresoMailing();



                        $i = 0;
                        while($i < $numBoletinesActivos){
                            $boletinesActivos = $boletin -> obtenerBoletinesConLimite($i);
                            foreach ($boletinesActivos as $boletinActivo) {
                                    $tempcorreo1= new tempcorreo4($idCorreo,0,$boletinActivo -> idBoletin);
                                    $tempcorreo1->enviar();
                                    $progresoMailing -> agregarUnEnviado();
                                    usleep(200000);
                            }
                            usleep(200000);
                            $i += 100;
                        }

                        $fechaYHoraFinal = date("Y-m-d h:i:sa");
                        $progresoMailing -> fechaYHoraFinal = $fechaYHoraFinal;
                        $progresoMailing -> status = 1;
                        $progresoMailing -> actualizarFechaYHoraFinal();
                        $progresoMailing -> actualizarStatus();

                    }

So this code what it does is tha it grabs all the registered e-mails in the database(BOLETIN) and since I don't want to load 38,400 objects in memory I limit the query to give me 100 results per query. After an e-mail has been sent (enviar) I make the process sleep .2 seconds just so the hosting doesn't go crazy. I handle a counter which tellms me number of e-mails sent, just so I can notifiy my client that the e-mails have been sent, and I display a progress bar, this is why I need to save the number of e-mails sent. So after an hour or so, the php process stopped around 11,000 e-mails were sent. I didn't find any failures or faults in the erro_log file, Why did the process stop? was it the OS? I appreciate any comments, tips or solutions to this problem. Thanks!!

役に立ちましたか?

解決

Most hosts (I think all of them that I have used) have limits on the number of emails an account is allowed to send either per hour or per day and probably both.

If you look at the hostgator email policy http://www.hostgator.com/mailpolicy it clearly states there are limits - I'm surprised you have actually managed to get to 11,000 sent! That is assuming they have actually been sent and that is not just a counter of the send function working (there is a difference in asking for something to be sent and it actually going). They could all be coming back as undelivered.

They recommend PHPlist which uses throttling to ensure you stay under you allowed limits and I have used it to send a large number (100k+) of emails in the past but unless you pay for hosting that will allow you to send high volumes of emails I can see you getting issues if you try and send that many that fast.

他のヒント

I suspect the max_execution_time

How to increase maximum execution time in php

Could also be the host restraining such behavior.

The most common error I could think of is that your script reached maximum execution time, or the script was not made to continue working if browser connection is lost.

Your best bet would be to not have one execution send all the mails, but run your script every 5 minutes and make it send 1500 (5mails per second if you sleep .2sec for each, time 5 minutes). Keep track of what has been sent so the script re-executing will continue where it left off.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top