El correo electrónico por lotes de SwiftMailer agota el tiempo de espera de mi servidor

I realise that batchEmail is no longer part of the new SwiftMailer. So I made this script:

<?
//
// GC PRESS EMAILER v5
//
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once("config.php");
include_once("hawkmail/mail/lib/swift_required.php");
$c=mysql_connect($dbh,$dbu,$dbp);
function SendEmail(){
    // DB
    $s=mysql_query("SELECT * FROM `newgc`.`press_list`");
    // Process Color Listing Loop
    while($r=mysql_fetch_array($s)){
    // ###########################
    // START LOOP
    // ###########################
        $name=$r['name'];
        $email=$r['email'];
        $to=array(''.$email.''=>''.$name.'');
        include("hawkmail/templates/press.php");
        # Email subject
        $str=$name;
        $str=substr($str, 0, strrpos($str, ' '));
        $subject='Dear '.$str.', you are invited to our Exclusive Party Collection Press Day!';
        # send message
        include("hawkmail/settings.php");       
    }
    // ###########################
    // END LOOP
    // ###########################
}
SendEmail();
?>

The database has 200 records. And I ran the script and it sends a few emails and then times out

504 Pasarela fuera

La name y email records are like

John Smith John.smith@site.com

Very plain. And my hawkmail/settings.php es la siguiente:

# mail
$smpturl="smtp.sendgrid.net";
$mailu="sitesitesite";
$mailp="sitessssssssssss";
$from=array("no-reply@site.com"=>"site.com");

# login credentials & setup Swift mailer parameters
$transport=Swift_SmtpTransport::newInstance($smpturl, 587);
$transport->setUsername($mailu);
$transport->setPassword($mailp);
$swift=Swift_Mailer::newInstance($transport);

# create a message (subject)
$message=new Swift_Message($subject);

# attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');

$message->setTo($to);
$message->addPart($text, 'text/plain');

# actually send the message
if($recipients=$swift->send($message, $failures)){}else{}

Is there anyway to increase the limit of PHP time out (I use Ubuntu and Nginx) or is there an alternative to BatchMail() really don't understand why it was removed.

Can someone post examples of Batch mail scripts using the new swiftmailer?

preguntado el 29 de agosto de 12 a las 13:08

Your loop should have worked I think. How about increasing server memory if cloud box to quickly execute the script? If running via browser maybe do a background task? (I dont know how to do on nginx or ubuntu if not got cPanel) -

PHP has a timeout limit you need a cron job I think -

1 Respuestas

Sending emails is the most complicated thing to do online.

It is the second most used service and the most abused.

I built my own custom email platform for sending bulk emails.

El tiempo de espera que experimenta se debe a los límites de ejecución de Apache y PHP.

Debe ejecutarlo como una aplicación CLI con set_time_limit (0);

php /path/to/app/script.php algo así directamente en la consola.

Si no tiene acceso SSH, ejecútelo con shell_exec Me gusta esto:

shell_exec("php /path/to/app/script.php > /dev/null 2>/dev/null &");

Esto asegurará que el script que lo llama no se detenga hasta que finalice.

Respondido el 01 de Septiembre de 12 a las 19:09

Thank you. This is what I was after. - elnegrobenzkid

I built my own custom email platform for sending bulk emails. Out of interest can you explain a little - is it opensource? - elnegrobenzkid

Nop. Not yet finished. So far I have the SMTP part done, still need to do the POP3 and IMAP, but that is one of my least concerns. I mainly needed the delivery and receiving part done in order to be able to send bulk emails and receive bounces that I can nicely parse on the spot and add to the delivery reports in order to identify if there are any invalid email addresses or other reason for failed delivery. I like doing things from scratch and something like this will shine on my resume. I will make parts of it public at some stage. - Transilvlad

do use Sendgrid as an SMTP service ? If not I recommend me. Even their integration and dev guides are simple to follow and adapt - best if your a Rackspace customer it is free. - elnegrobenzkid

Nop. Like I said I built everything myself. From scratch with just Python, PHP and Notepad. - Transilvlad

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.