0

Let's assume we have a 2000 email list with newsletter subscribers and we need to mass email them. Servers do have hourly limitations when sending emails to prevent SPAM.

Some have 300 or even 500 emails per hour which is fair enough.

While using swiftmailer throttle plugin to send for example 8 emails per minute (8 * 60 minutes = 480 total mails which is under the 500 limit) server closes the connection and responds with a "404 - Not found page".

The weird thing is that it has sent 100 or less email during script execution but still server treats the procedure as it has fallen to an infinite loop and terminates the script execution.

If I try to send 500 emails at once without the throttle plugin it works like a charm. But what if I need to send more emails like 1500 or 2000?

I've read the the throttle plugin uses PHP's native function sleep() which should work properly in a situation like this one.

I was informed that it could work if the process is executed through Cron Job and not through the HTTP protocol. I've tried that using wget and curl to set up the cron job but still no luck.

What I've learned from the research I conducted is that when using an SMTP server with Swiftmailer a 3 second process takes 28 seconds (way longer than it should). All queries all optimized and all data are properly placed in memory without overloading the server.

After that I decided to give it a shot without using SMTP but the Throttler Plugin didn't work as it should (again).

Any suggestions or recommendations would be highly appreciated.

EDIT: I've also read this: SwiftMailer Batch email times my Server out

Of course I use this:

ignore_user_abort(true);
set_time_limit(0);
ini_set('max_execution_time', 0);
ini_set('memory_limit', '256M');
ini_set('mysql.connect_timeout', 500);
ini_set('default_socket_timeout', 500);

P.S.: I was forced to change the script's behavior for now so that it calculates the server's limit based on user input for emails per minute and if the total number of active subscribers is LESS OR EQUAL to the emails that are going to be send out, it sends them without the throttle plugin.

Warmest Regards, George Girtsou

Community
  • 1
  • 1
ggirtsou
  • 2,050
  • 2
  • 20
  • 33

1 Answers1

3

I think that this has to do with timeout of your SMTP connection.

When you process your emails in a loop and combined with the Throttle Plugin, Swiftmailer doesn't get the chance to close the connection with the SMTP server, and that one might have a limitation of the number of emails sent in ONE single connection as well.

That's why it's advisable to get the AntiFlood plugin into the combination as well, which closes the SMTP connection after x mails being sent and waits y seconds until reconnect.

$transport->start() and $transport->stop() are the manual methods to connect and disconnect from the SMTP server, which the plugins are using.

For SMTP transport, there's a timeout parameter as well that might be interesting for you.

It's also good to have your code in try{} catch{} for nice error handling.

Hope this helps, even it's kind of late for you !

qdev
  • 1,371
  • 1
  • 15
  • 18