Jump to content

Sending a batch of emails from one page


DWilliams

Recommended Posts

I'm curious about the mechanics of the script execution here.

 

One page in my project sends out batch emails to all users who are registered. That part is simlple enough, but in order to do it, my page has to connect to a remote SMTP server and then submit all the recipients and messages. This process can take a little bit of time, usually 5 seconds or so. If the user hits the stop button or navigates away while my script is still executing, will it mess up the emails that are being sent?

 

If so, what other way should I restructure my script to make it more robust? The first thing that comes to my mind is adding them to some sort of queue in the database and then have a separate script that checks periodically for messages that need to be sent and then send them. The only way to do this, though, would be to make a script designed to be called by cron, and that somewhat complicated the installation of my script which I'd like to avoid.

Link to comment
https://forums.phpfreaks.com/topic/217316-sending-a-batch-of-emails-from-one-page/
Share on other sites

You could use exec() to execute the script and send the output to /dev/null (if you don't want to wait for execution to be complete). The script would continue regardless of whether the user kept their browser open.

 

However, having a queue is probably a far more robust solution. ;)

You could use exec() to execute the script and send the output to /dev/null (if you don't want to wait for execution to be complete). The script would continue regardless of whether the user kept their browser open.

 

However, having a queue is probably a far more robust solution. ;)

 

Hmm I like that idea. Does exec() launch its target in a separate process? I would assume so, otherwise I wouldn't be making any progress if the new line of execution joined the current process.

 

Assuming it IS launched in a separate process, how can I make my exec'd script uncallable from the web browser? If I make a processSendQueue.php, I wouldn't want somebody to be able to call it via the web path like example.com/processSendQueue.php. I know the obvious way of doing that is to put it outside the web root but that also complicates installation and I don't think safe mode will allow that anyway.

I don't know. But I would take a different approach and insert all emails into a database and have a separate PHP script run via crontab job run to send them out in batches.

 

Yeah that's the first thing that came to mind for me but as stated I don't want to do that if I can avoid it since requiring a cron script compounds installation complexity.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.