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
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. ;)

Link to comment
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. ;)

 

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.