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!!