sending email with pause of 2 seconds between emails

0

I have the Swiftmailer library sending the emails correctly, but I would like to pause for 2 seconds between sending the various emails in my array. I tried to use sleep(2) in the loop, but it does not work.

How can I do this?

$users = unserialize($_POST['result']);

print_r($array);

// Create the replacements array
$replacements = array();
foreach ($users as $user) {
  $replacements[$user["email"]] = array (
    "{nome}" => $user["nome"],
    "{total}" => $user["total"]
  );

}

// Create the mail transport configuration
$transport = Swift_MailTransport::newInstance();

// Create an instance of the plugin and register it
$plugin = new Swift_Plugins_DecoratorPlugin($replacements);
$mailer = Swift_Mailer::newInstance($transport);
$mailer->registerPlugin($plugin);

// Create the message
$message = Swift_Message::newInstance();
$message->setSubject("Pedido de recibos ");

// $message->setBody("Olá {nome}, agradecemos desde já a sua colaboração durante o mês de $mesde . " .
//     "Deverá enviar um recibo no total de : {total}€ para [email protected] no prazo limite de 5 dias");


$message->setBody("Bom dia {nome},

email msg

");


$message->setFrom("[email protected]", "Top");
// Send the email
foreach($users as $user) {sleep(2);
  $message->setTo($user["email"], $user["nome"]);
  $mailer->send($message);
    
asked by anonymous 15.01.2016 / 12:57

0 answers