eddy
eddy

Reputation:

Email queueing in php

What is the most proper way to sending email of minimal 1000 or more in PHP? Any reliable email queuing technique that is capable to handle that? ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

Upvotes: 5

Views: 7610

Answers (7)

Loren
Loren

Reputation: 94

I created Emailqueue, which is a server that allows you to add emails to a queue so your app get relieved of the stress of the mailing, and also provides useful additional options, like the ability to program emails to be sent in the future, or setting per-email sending priorities. I think this might very well be what you're searching for.

Emailqueue is available here: https://github.com/tin-cat/emailqueue

And there is also a Docker version that allows you to set up a working Emailqueue server in just a few minutes, here: https://github.com/tin-cat/emailqueue-docker

Upvotes: 1

rix0rrr
rix0rrr

Reputation: 10266

Are you sure you need do this mail queuing yourself?

Just deliver all mail to the local machine's mail transfer agent (sendmail...) and let that take care of the queuing and sending. After all, that's what was designed for.

In other words: don't worry about it!

Upvotes: 1

BlaM
BlaM

Reputation: 28858

There's a tested solution for that: PEAR Mail_Queue

Works fine for me.

Upvotes: 2

Erik van Brakel
Erik van Brakel

Reputation: 23820

Sure, the database table might be an idea. But what about sending 1000 e-mails with a 2mb attachment? you'd have to take that into account as well. I had the problem myself, and I eventually resorted to writing the e-mail to the database, and the files to the filesystem. The e-mail script I used then read the database records, and tried to fetch the attachments to send.

Upvotes: 1

JimmyJ
JimmyJ

Reputation: 4441

as mercutio suggested, i would insert a new record into a mail queue table for each email waiting to be sent and then use a separate process (like a CRON) to check the table periodically for any queued items.

if any emails are queued (and the email is not customised for each recipient) i would then group the emails by domain and send blocks together to reduce the total number of emails that have to be sent, i.e. if you have 1000 emails queued and 250 are to gmail accounts i would send the 250 in 25 blocks of 10 (remember to Bcc recipients to avoid them seeing each other).

to actually send the mail i would use PEAR mail over php's mail() function

after sending the email either delete record(s) from the queue or change a status flag to show it was sent and loop - i would also add a counter to keep track of emails that failed to send and remove them after x failed attempts

to overcome timeout issues i would either,(depending on the situation) - set the set_time_limit() to x seconds and keep track of the script execution time (killing the script after (x-1) seconds) - call the script from the command line to avoid timeouts - set a limit to the number of emails the script could send in one execution

Upvotes: 1

Matt Mitchell
Matt Mitchell

Reputation: 41823

I've generally relied on a hack. I have a database list of email addresses and then use a meta-redirect to self with an increasing 'offset' parameter that specifies which row in the database I am up to. Server redirects cause problems because browsers assume that the time taken indicates an infinite loop.

Upvotes: 0

mercutio
mercutio

Reputation: 22577

You could just insert your emails into a Mail Queue database table, and have a separate process check the queue and batch send a certain number at once.

Upvotes: 6

Related Questions