Class Summary Mail_Queue | constructor Mail_Queue::Mail_Queue |
Mail_Queue | |
PEAR Manual | |
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:
mysql.sql
CREATE TABLE mail_queue ( id bigint(20) NOT NULL default '0', create_time datetime NOT NULL default '0000-00-00 00:00:00', time_to_send datetime NOT NULL default '0000-00-00 00:00:00', sent_time datetime default NULL, id_user bigint(20) NOT NULL default '0', ip varchar(20) NOT NULL default 'unknown', sender varchar(50) NOT NULL default '', recipient text NOT NULL, headers text NOT NULL, body longtext NOT NULL, try_sent tinyint(4) NOT NULL default '0', delete_after_send tinyint(1) NOT NULL default '1', PRIMARY KEY (id), KEY id (id), KEY time_to_send (time_to_send), KEY id_user (id_user) ); |
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
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:
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:
send_messages.php
|
We are done. Now run the last script regularly and add your mails to the queue as needed.
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.
You can also send the stored emails one by one. Here is a simple script to achieve this:
send_messages_one_by_one.php
|
Class Summary Mail_Queue | constructor Mail_Queue::Mail_Queue |
Mail_Queue | |
PEAR Manual | |