Using cron to send bulk email on a shared host

I’m running a conference booking system at and we need to send out lots of emails to delegates and potential delegates. Our host only allows 100 emails per hour from the website, so I needed to find a way of queueing them and sending in batches…

First a mysql db table…

I’ve not set up attachments yet, so that table continues everything else we need.

Here’s a function to queue messages

I tend to call it with some basic messaging

So that handles creating messages and storing them in the database queue.

Here’s my cronemail.php file

The code is well commented – make sure you replace the hashes!

You will also need the excellent phpmailer script

Now we need to set up our shared host to execute cronemail.php every hour!

Go to your CPANEL and click on cron jobs – on my version there is a standard link and an advanced link

I use standard!

Common settings gives you some common options – once an hour is what we want (although for testing once every five minutes would be less tedious)

The command to run took a bit longer to get right! A lot of blog posts get this bit wrong!!!

You need to find out your php path – most likely to be /usr/local/bin/php

Then you need the path to the script – best put in a non-public accessable area or in the document root if you must!


So now you can type

/usr/local/bin/php -f /home/(username)/public_html/cronemail.php

into the command to run field and press . The -f tells the php compiler to run the file. Don’t forget to change (username) to your username.

Hope it helps…
Here it is in a zip file with a tester script index.php –emailstuff. Don’t use index.php in a production environment as there is no form checking!

4 Comments on “Using cron to send bulk email on a shared host”

  • Filipe Rudá September 7th, 2012 11:30 pm

    Excelente tutorial, me ajudou com um perrengue. Eu estava utilizando:
    / Usr / local / bin / php -c / home / (username) / www cronemail.php /
    quando deveria utilizar:
    / Usr / local / bin / php -c / home / (username) / public_html cronemail.php /
    A diferença era o WWW para PUBLIC_HTML libera o acesso aos arquivos para serem anexados também
    Não sei a diferença de -f para -c, só que trava com -f e funfa com o -c

  • admin September 20th, 2012 6:54 pm

    Thanks for the excellent tutorial comment, but I don’t speak Spanish! I’m guessing you needed to use public_html in the path which is better anyway. The “www” folder is usually a mirror of “public_html” anyway!

  • A Leasdon February 1st, 2013 5:23 pm


    An old topic I know! And slightly unrelated but I’d be interested to know where you got the information regarding the emails per hour limit from UK2?

    I’ve been in contact with the support team but they have stated they do not allow mass mails from a shared business hosting account and have so far not divulged the limit per hour, which will obviously exist.

    Any info would be helpful.

    Thanks in advance.


  • admin February 1st, 2013 5:48 pm

    Don’t use the word “mass email” with any hosting company – makes you sound like a spammer! I told them what I was sending – booking emails generated by an online booking system.

    The problem with sending email using mail() from UK2 is that their default setting is to send it from the shared server’s IP which will most likely have been blacklisted as spam by other users misuse. So ask for your own IP address (which you would have anyway if you have an ssl on the domain) and then ask them to set mail() to send from your own IP. They told me 100 emails max per hour, when I asked.

Leave a Reply