2-second pause between emails

Asked

Viewed 103 times

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?

  • to avoid k being interpreted as spam...is not really a newsletter...are legit emails automated and sent by the site...

  • Do not need delay ( Sleep() to avoid being characterized as spam.

  • my server told me to send 50 max emails for every 10 min ... that’s why also...my emails are authenticated...

  • @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).

  • 1

    Why don’t you use Cron?

  • I’ll see how it works

  • I can’t pause 2 seconds between shipments :(

Show 3 more comments

1 answer

-2


You send mass emails?

If so, I suggest you lower the frequency of sending emails, since Gmail has these limits. Learn more: Limits for sending and receiving emails

You added a large group of recipients to the "Cc" or "Cco" field".?

If yes, learn more how to: Fix bounced or declined email errors

I suggest you also see problems with bulk email senders

2°-How long can I restore my email for sending?

this error, it will be possible to send emails again after 1 to 24 hours

Browser other questions tagged

You are not signed in. Login or sign up in order to post.