0
I have the Swiftmailer library sending the emails correctly, but I would like to pause 2 seconds between submissions of the various emails in my array. I tried to use the sleep(2)
in the loop, but it doesn’t 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);
This is to prevent spam?
– rray
to avoid k being interpreted as spam...is not really a newsletter...are legit emails automated and sent by the site...
– I-am Sam
Do not need delay ( Sleep() to avoid being characterized as spam.
– Daniel Omine
my server told me to send 50 max emails for every 10 min ... that’s why also...my emails are authenticated...
– I-am Sam
@rray do not know why do this, but I’ve seen this operation in several email sending libraries. Usually the assignment of the methods they do to this is called "Queue" (fila).
– Wallace Maxters
Why don’t you use Cron?
– Marco Aurélio Deleu
I’ll see how it works
– I-am Sam
I can’t pause 2 seconds between shipments :(
– I-am Sam