We are using the db-container for the example and a mysql database. You need to create some tables in the mysql-database to store the messages:
Example 46-1. mysql.sql
|
First you need to define some options. As you need them two times (once for adding messages, once for sending the messages) its always good to add them to a config-file. Lets call it config.php
Example 46-2. config.php
|
So we are done configuring it, now let's use it. First we need to construct a mail-message and add it to the queue:
Example 46-3. add_message.php
|
Ok, now we've used the simple way to add a message ... there are more advanced options, please check docs of the put-function for these. Now we need to send the messages. This is most often done by using a cron-job which regularly runs a script to send the messages. Here is a simple script to achieve this:
Example 46-4. send_messages.php
|
Since Mail_Queue v.1.1, the preload() method doesn't preload ALL the mails in memory, but just a few of them each time. When the buffer is empty, it is filled again automatically. You can set the size of the buffer via the new setBufferSize() method.
Example 46-5. send_messages_one_by_one.php
|