![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
04/01/2007, 16:31
|
| | Fecha de Ingreso: febrero-2002 Ubicación: Chile
Mensajes: 1.573
Antigüedad: 23 años Puntos: 2 | |
Re: Varios emails, uso de memoria y CPU Esto fue usando phpmailer
hago un loop conm los emails obtenidos de la DB y envio cada X segundos, por "background", asi el cliente puede cerrar la ventana
Saludos Código PHP: set_time_limit(84000); //antes le inidco que el script puede demorarse varias horas en ejecutarse.. y q no lo mate function enorme($qcl,$rem) { require_once($_SERVER['DOCUMENT_ROOT']."/admin/emails/class.phpmailer.php");
while ($rcl = mysql_fetch_array($qcl)) { $asunto=$rem['asunto']; $asunto=str_replace("[!rut!]", $rcl['rut'] , $asunto); $asunto=str_replace("[!nombre!]", $rcl['nombre'] , $asunto); $asunto=str_replace("[!apellido!]", $rcl['apellido'] , $asunto); $asunto=str_replace("[!email!]", $rcl['email_1'] , $asunto); $asunto=str_replace("[!direccion!]", $rcl['direccion'] , $asunto); $asunto=str_replace("[!fecha!]", date("d-m-Y"), $asunto); $texto=$rem['cuerpo']; $texto=str_replace("[!rut!]", $rcl['rut'] , $texto); $texto=str_replace("[!nombre!]", $rcl['nombre'] , $texto); $texto=str_replace("[!apellido!]", $rcl['apellido'] , $texto); $texto=str_replace("[!email!]", $rcl['email_1'] , $texto); $texto=str_replace("[!direccion!]", $rcl['direccion'] , $texto); $texto=str_replace("[!fecha!]", date("d-m-Y"), $texto);
//$cabeceras = "MIME-Version: 1.0\r\n"; //$cabeceras .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mail = new PHPMailer(); $mail->Mailer = "smtp"; $mail->Host = "viva.chile.cl"; $mail->SMTPAuth = true; $mail->Username = "VIVACHILE"; $mail->Password = "VIVACHILE"; $mail->From = "[email protected]"; $mail->FromName = "Grande chile!"; $mail->ContentType= "text/html"; $mail->Timeout=10;
$mail->AddAddress($rcl['email_1']); $mail->Subject = $asunto; $mail->Body = html_entity_decode($texto); //$mail->Body = "<b>ahahaha</b>"; $exito = $mail->Send(); $intentos=1; while ((!$exito) && ($intentos < 5)) { sleep(5); $exito = $mail->Send(); $intentos=$intentos+1; } if(!$exito){ $msg_E= "Problemas enviando correo electr�ico a ".$valor."<br/>".$mail->ErrorInfo; mail("[email protected]","Error envio lista correo",$msg_E); } // flush();
sleep(2);// dormir dos segundos entre conexion al smtp } }
register_shutdown_function(enorme,$qcl,$rem);
Última edición por NRLABS; 04/01/2007 a las 16:48 |