cvs: peardoc /en/package/mail/mail-queue/mail-queue tutorial.xml
| From: | Lorenzo Alberton | Date: | Sat, 12 Jun 2004 23:00:46 +0000 |
| Subject: | cvs: peardoc /en/package/mail/mail-queue/mail-queue tutorial.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-4391@lists.php.net to get a copy of this message | ||
quipo Sat Jun 12 19:00:46 2004 EDT
Modified files:
/peardoc/en/package/mail/mail-queue/mail-queue tutorial.xml
Log:
unix LF
http://cvs.php.net/diff.php/peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml?r1=1.4&r2=1.5&ty=u Index: peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml diff -u peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml:1.4 peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml:1.5 --- peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml:1.4 Sat Jun 12 16:54:56 2004 +++ peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml Sat Jun 12 19:00:46 2004 @@ -1,279 +1,279 @@ -<!-- $Revision: 1.4 $ --> -<refentry id="package.mail.mail-queue.mail-queue.tutorial"> - <refnamediv> - <refname>Tutorial</refname> - <refpurpose>A tutorial for Mail_Queue</refpurpose> - </refnamediv> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part1"> -<title>Mail_Queue usage with a simple example</title> -<para> -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: -</para> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part2"> -<title /> -<para> - <example> - <title>mysql.sql</title> - <programlisting role="sql"> -<![CDATA[ -# -# `mail_queue` -# - -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 varchar(50) NOT NULL default '', - 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) -); - -# -# `mail_queue_seq` -# - -CREATE TABLE mail_queue_seq ( - id int(10) unsigned NOT NULL auto_increment, - PRIMARY KEY (id) -); - -# -# Data for `mail_queue_seq` -# - -INSERT INTO mail_queue_seq (id) VALUES (1); -]]> - -</programlisting> -</example> -</para> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part3"> -<title /> -<para> -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 -</para> -</refsect1> - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part4"> -<title /> - <example> - <title>config.php</title> - <programlisting role="php"> -<![CDATA[ -<?php - -require_once "Mail/Queue.php"; - -// options for storing the messages -// type is the container used, currently there are db and mdb available -$db_options['type'] = 'db'; -// the others are the options for the used container -// here are some for db -$db_options['dsn'] = 'mysql://user:password@host/database'; -$db_options['mail_table'] = 'mail_queue'; - -// here are the options for sending the messages themselves -// these are the options needed for the Mail-Class, especially used for Mail::factory() -$mail_options['driver'] = 'smtp'; -$mail_options['host'] = 'your_server_smtp.com'; -$mail_options['port'] = 25; -$mail_options['auth'] = false; -$mail_options['username'] = ''; -$mail_options['password'] = ''; - -?> -]]> - -</programlisting> -</example> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part5"> -<title /> -<para> -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: -</para> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part6"> -<title /> - <example> - <title>add_message.php</title> - <programlisting role="php"> -<![CDATA[ -<?php -include './config.php'; -/* we use the db_options and mail_options here */ -$mail_queue =& new Mail_Queue($db_options, $mail_options); - - -$from = 'user@server.com'; -$to = "user2@server.com"; -$message = 'Hi! This is test message!! :)'; - -$hdrs = array( 'From' => $from, - 'To' => $to, - 'Subject' => "test message body" ); - -/* we use Mail_mime() to construct a valid mail */ -$mime =& new Mail_mime(); -$mime->setTXTBody($message); -$body = $mime->get(); -$hdrs = $mime->headers($hdrs); - - -/* Put message to queue */ -$mail_queue->put( $from, $to, $hdrs, $body ); - -?> -]]> - -</programlisting> -</example> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part7"> -<title /> -<para> -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: -</para> -</refsect1> - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part8"> -<title /> - <example> - <title>send_messages.php</title> - <programlisting role="php"> -<![CDATA[ -<?php -include './config.php'; - -/* How many mails could we send each time the script is called */ -$max_amount_mails = 50; - -/* we use the db_options and mail_options from the config again */ -$mail_queue =& new Mail_Queue($db_options, $mail_options); - -/* really sending the messages */ -$mail_queue->sendMailsInQueue($max_amount_mails); -?> -]]> - -</programlisting> -</example> -</refsect1> - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part9"> -<title /> -<para> -We are done. -Now run the last script regularly and add your mails to the queue as needed. -</para> -</refsect1> - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part10"> -<title /> -<para> -Since <classname>Mail_Queue</classname> v.1.1, the <function>preload</function> -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 <function>setBufferSize</function> method. -</para> -</refsect1> - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part11"> -<title /> -<para> -You can also send the stored emails one by one. -Here is a simple script to achieve this: -</para> -</refsect1> - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part12"> -<title /> - <example> - <title>send_messages_one_by_one.php</title> - <programlisting role="php"> -<![CDATA[ -<?php -/* set the internal buffer size according your */ -/* memory resources (the number indicates how */ -/* many emails can stay in the buffer at any */ -/* given time */ - +<!-- $Revision: 1.5 $ --> +<refentry id="package.mail.mail-queue.mail-queue.tutorial"> + <refnamediv> + <refname>Tutorial</refname> + <refpurpose>A tutorial for Mail_Queue</refpurpose> + </refnamediv> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part1"> +<title>Mail_Queue usage with a simple example</title> +<para> +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: +</para> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part2"> +<title /> +<para> + <example> + <title>mysql.sql</title> + <programlisting role="sql"> +<![CDATA[ +# +# `mail_queue` +# + +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 varchar(50) NOT NULL default '', + 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) +); + +# +# `mail_queue_seq` +# + +CREATE TABLE mail_queue_seq ( + id int(10) unsigned NOT NULL auto_increment, + PRIMARY KEY (id) +); + +# +# Data for `mail_queue_seq` +# + +INSERT INTO mail_queue_seq (id) VALUES (1); +]]> + +</programlisting> +</example> +</para> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part3"> +<title /> +<para> +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 +</para> +</refsect1> + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part4"> +<title /> + <example> + <title>config.php</title> + <programlisting role="php"> +<![CDATA[ +<?php + +require_once "Mail/Queue.php"; + +// options for storing the messages +// type is the container used, currently there are db and mdb available +$db_options['type'] = 'db'; +// the others are the options for the used container +// here are some for db +$db_options['dsn'] = 'mysql://user:password@host/database'; +$db_options['mail_table'] = 'mail_queue'; + +// here are the options for sending the messages themselves +// these are the options needed for the Mail-Class, especially used for Mail::factory() +$mail_options['driver'] = 'smtp'; +$mail_options['host'] = 'your_server_smtp.com'; +$mail_options['port'] = 25; +$mail_options['auth'] = false; +$mail_options['username'] = ''; +$mail_options['password'] = ''; + +?> +]]> + +</programlisting> +</example> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part5"> +<title /> +<para> +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: +</para> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part6"> +<title /> + <example> + <title>add_message.php</title> + <programlisting role="php"> +<![CDATA[ +<?php +include './config.php'; +/* we use the db_options and mail_options here */ +$mail_queue =& new Mail_Queue($db_options, $mail_options); + + +$from = 'user@server.com'; +$to = "user2@server.com"; +$message = 'Hi! This is test message!! :)'; + +$hdrs = array( 'From' => $from, + 'To' => $to, + 'Subject' => "test message body" ); + +/* we use Mail_mime() to construct a valid mail */ +$mime =& new Mail_mime(); +$mime->setTXTBody($message); +$body = $mime->get(); +$hdrs = $mime->headers($hdrs); + + +/* Put message to queue */ +$mail_queue->put( $from, $to, $hdrs, $body ); + +?> +]]> + +</programlisting> +</example> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part7"> +<title /> +<para> +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: +</para> +</refsect1> + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part8"> +<title /> + <example> + <title>send_messages.php</title> + <programlisting role="php"> +<![CDATA[ +<?php +include './config.php'; + +/* How many mails could we send each time the script is called */ +$max_amount_mails = 50; + +/* we use the db_options and mail_options from the config again */ +$mail_queue =& new Mail_Queue($db_options, $mail_options); + +/* really sending the messages */ +$mail_queue->sendMailsInQueue($max_amount_mails); +?> +]]> + +</programlisting> +</example> +</refsect1> + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part9"> +<title /> +<para> +We are done. +Now run the last script regularly and add your mails to the queue as needed. +</para> +</refsect1> + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part10"> +<title /> +<para> +Since <classname>Mail_Queue</classname> v.1.1, the <function>preload</function> +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 <function>setBufferSize</function> method. +</para> +</refsect1> + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part11"> +<title /> +<para> +You can also send the stored emails one by one. +Here is a simple script to achieve this: +</para> +</refsect1> + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part12"> +<title /> + <example> + <title>send_messages_one_by_one.php</title> + <programlisting role="php"> +<![CDATA[ +<?php +// set the internal buffer size according your +// memory resources (the number indicates how +// many emails can stay in the buffer at any +// given time + $mail_queue->setBufferSize(20); -/* loop through the stored emails and send them */ -while ($mail = $mail_queue->get()) { - $result = $mail_queue->sendMail($mail); +// loop through the stored emails and send them +while ($mail = $mail_queue->get()) { + $result = $mail_queue->sendMail($mail); } -?> -]]> - -</programlisting> -</example> -</refsect1> - -</refentry> - -<!-- Keep this comment at the end of the file -Local variables: -mode: sgml -sgml-omittag:t -sgml-shorttag:t -sgml-minimize-attributes:nil -sgml-always-executeMultiple-attributes:t -sgml-indent-step:1 -sgml-indent-data:t -sgml-parent-document:nil -sgml-default-dtd-file:"../../../../manual.ced" -sgml-exposed-tags:nil -sgml-local-catalogs:nil -sgml-local-ecat-files:nil -End: -vim600: syn=xml fen fdm=syntax fdl=2 si -vim: et tw=78 syn=sgml -vi: ts=1 sw=1 ---> +?> +]]> + +</programlisting> +</example> +</refsect1> + +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-executeMultiple-attributes:t +sgml-indent-step:1 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:"../../../../manual.ced" +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +vim600: syn=xml fen fdm=syntax fdl=2 si +vim: et tw=78 syn=sgml +vi: ts=1 sw=1 +-->
http://cvs.php.net/diff.php/peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml?r1=1.4&r2=1.5&ty=u Index: peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml diff -u peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml:1.4 peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml:1.5 --- peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml:1.4 Sat Jun 12 16:54:56 2004 +++ peardoc/en/package/mail/mail-queue/mail-queue/tutorial.xml Sat Jun 12 19:00:46 2004 @@ -1,279 +1,279 @@ -<!-- $Revision: 1.4 $ --> -<refentry id="package.mail.mail-queue.mail-queue.tutorial"> - <refnamediv> - <refname>Tutorial</refname> - <refpurpose>A tutorial for Mail_Queue</refpurpose> - </refnamediv> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part1"> -<title>Mail_Queue usage with a simple example</title> -<para> -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: -</para> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part2"> -<title /> -<para> - <example> - <title>mysql.sql</title> - <programlisting role="sql"> -<![CDATA[ -# -# `mail_queue` -# - -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 varchar(50) NOT NULL default '', - 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) -); - -# -# `mail_queue_seq` -# - -CREATE TABLE mail_queue_seq ( - id int(10) unsigned NOT NULL auto_increment, - PRIMARY KEY (id) -); - -# -# Data for `mail_queue_seq` -# - -INSERT INTO mail_queue_seq (id) VALUES (1); -]]> - -</programlisting> -</example> -</para> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part3"> -<title /> -<para> -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 -</para> -</refsect1> - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part4"> -<title /> - <example> - <title>config.php</title> - <programlisting role="php"> -<![CDATA[ -<?php - -require_once "Mail/Queue.php"; - -// options for storing the messages -// type is the container used, currently there are db and mdb available -$db_options['type'] = 'db'; -// the others are the options for the used container -// here are some for db -$db_options['dsn'] = 'mysql://user:password@host/database'; -$db_options['mail_table'] = 'mail_queue'; - -// here are the options for sending the messages themselves -// these are the options needed for the Mail-Class, especially used for Mail::factory() -$mail_options['driver'] = 'smtp'; -$mail_options['host'] = 'your_server_smtp.com'; -$mail_options['port'] = 25; -$mail_options['auth'] = false; -$mail_options['username'] = ''; -$mail_options['password'] = ''; - -?> -]]> - -</programlisting> -</example> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part5"> -<title /> -<para> -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: -</para> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part6"> -<title /> - <example> - <title>add_message.php</title> - <programlisting role="php"> -<![CDATA[ -<?php -include './config.php'; -/* we use the db_options and mail_options here */ -$mail_queue =& new Mail_Queue($db_options, $mail_options); - - -$from = 'user@server.com'; -$to = "user2@server.com"; -$message = 'Hi! This is test message!! :)'; - -$hdrs = array( 'From' => $from, - 'To' => $to, - 'Subject' => "test message body" ); - -/* we use Mail_mime() to construct a valid mail */ -$mime =& new Mail_mime(); -$mime->setTXTBody($message); -$body = $mime->get(); -$hdrs = $mime->headers($hdrs); - - -/* Put message to queue */ -$mail_queue->put( $from, $to, $hdrs, $body ); - -?> -]]> - -</programlisting> -</example> -</refsect1> - - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part7"> -<title /> -<para> -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: -</para> -</refsect1> - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part8"> -<title /> - <example> - <title>send_messages.php</title> - <programlisting role="php"> -<![CDATA[ -<?php -include './config.php'; - -/* How many mails could we send each time the script is called */ -$max_amount_mails = 50; - -/* we use the db_options and mail_options from the config again */ -$mail_queue =& new Mail_Queue($db_options, $mail_options); - -/* really sending the messages */ -$mail_queue->sendMailsInQueue($max_amount_mails); -?> -]]> - -</programlisting> -</example> -</refsect1> - - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part9"> -<title /> -<para> -We are done. -Now run the last script regularly and add your mails to the queue as needed. -</para> -</refsect1> - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part10"> -<title /> -<para> -Since <classname>Mail_Queue</classname> v.1.1, the <function>preload</function> -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 <function>setBufferSize</function> method. -</para> -</refsect1> - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part11"> -<title /> -<para> -You can also send the stored emails one by one. -Here is a simple script to achieve this: -</para> -</refsect1> - -<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part12"> -<title /> - <example> - <title>send_messages_one_by_one.php</title> - <programlisting role="php"> -<![CDATA[ -<?php -/* set the internal buffer size according your */ -/* memory resources (the number indicates how */ -/* many emails can stay in the buffer at any */ -/* given time */ - +<!-- $Revision: 1.5 $ --> +<refentry id="package.mail.mail-queue.mail-queue.tutorial"> + <refnamediv> + <refname>Tutorial</refname> + <refpurpose>A tutorial for Mail_Queue</refpurpose> + </refnamediv> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part1"> +<title>Mail_Queue usage with a simple example</title> +<para> +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: +</para> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part2"> +<title /> +<para> + <example> + <title>mysql.sql</title> + <programlisting role="sql"> +<![CDATA[ +# +# `mail_queue` +# + +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 varchar(50) NOT NULL default '', + 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) +); + +# +# `mail_queue_seq` +# + +CREATE TABLE mail_queue_seq ( + id int(10) unsigned NOT NULL auto_increment, + PRIMARY KEY (id) +); + +# +# Data for `mail_queue_seq` +# + +INSERT INTO mail_queue_seq (id) VALUES (1); +]]> + +</programlisting> +</example> +</para> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part3"> +<title /> +<para> +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 +</para> +</refsect1> + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part4"> +<title /> + <example> + <title>config.php</title> + <programlisting role="php"> +<![CDATA[ +<?php + +require_once "Mail/Queue.php"; + +// options for storing the messages +// type is the container used, currently there are db and mdb available +$db_options['type'] = 'db'; +// the others are the options for the used container +// here are some for db +$db_options['dsn'] = 'mysql://user:password@host/database'; +$db_options['mail_table'] = 'mail_queue'; + +// here are the options for sending the messages themselves +// these are the options needed for the Mail-Class, especially used for Mail::factory() +$mail_options['driver'] = 'smtp'; +$mail_options['host'] = 'your_server_smtp.com'; +$mail_options['port'] = 25; +$mail_options['auth'] = false; +$mail_options['username'] = ''; +$mail_options['password'] = ''; + +?> +]]> + +</programlisting> +</example> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part5"> +<title /> +<para> +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: +</para> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part6"> +<title /> + <example> + <title>add_message.php</title> + <programlisting role="php"> +<![CDATA[ +<?php +include './config.php'; +/* we use the db_options and mail_options here */ +$mail_queue =& new Mail_Queue($db_options, $mail_options); + + +$from = 'user@server.com'; +$to = "user2@server.com"; +$message = 'Hi! This is test message!! :)'; + +$hdrs = array( 'From' => $from, + 'To' => $to, + 'Subject' => "test message body" ); + +/* we use Mail_mime() to construct a valid mail */ +$mime =& new Mail_mime(); +$mime->setTXTBody($message); +$body = $mime->get(); +$hdrs = $mime->headers($hdrs); + + +/* Put message to queue */ +$mail_queue->put( $from, $to, $hdrs, $body ); + +?> +]]> + +</programlisting> +</example> +</refsect1> + + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part7"> +<title /> +<para> +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: +</para> +</refsect1> + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part8"> +<title /> + <example> + <title>send_messages.php</title> + <programlisting role="php"> +<![CDATA[ +<?php +include './config.php'; + +/* How many mails could we send each time the script is called */ +$max_amount_mails = 50; + +/* we use the db_options and mail_options from the config again */ +$mail_queue =& new Mail_Queue($db_options, $mail_options); + +/* really sending the messages */ +$mail_queue->sendMailsInQueue($max_amount_mails); +?> +]]> + +</programlisting> +</example> +</refsect1> + + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part9"> +<title /> +<para> +We are done. +Now run the last script regularly and add your mails to the queue as needed. +</para> +</refsect1> + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part10"> +<title /> +<para> +Since <classname>Mail_Queue</classname> v.1.1, the <function>preload</function> +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 <function>setBufferSize</function> method. +</para> +</refsect1> + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part11"> +<title /> +<para> +You can also send the stored emails one by one. +Here is a simple script to achieve this: +</para> +</refsect1> + +<refsect1 id="package.mail.mail-queue.mail-queue.tutorial.part12"> +<title /> + <example> + <title>send_messages_one_by_one.php</title> + <programlisting role="php"> +<![CDATA[ +<?php +// set the internal buffer size according your +// memory resources (the number indicates how +// many emails can stay in the buffer at any +// given time + $mail_queue->setBufferSize(20); -/* loop through the stored emails and send them */ -while ($mail = $mail_queue->get()) { - $result = $mail_queue->sendMail($mail); +// loop through the stored emails and send them +while ($mail = $mail_queue->get()) { + $result = $mail_queue->sendMail($mail); } -?> -]]> - -</programlisting> -</example> -</refsect1> - -</refentry> - -<!-- Keep this comment at the end of the file -Local variables: -mode: sgml -sgml-omittag:t -sgml-shorttag:t -sgml-minimize-attributes:nil -sgml-always-executeMultiple-attributes:t -sgml-indent-step:1 -sgml-indent-data:t -sgml-parent-document:nil -sgml-default-dtd-file:"../../../../manual.ced" -sgml-exposed-tags:nil -sgml-local-catalogs:nil -sgml-local-ecat-files:nil -End: -vim600: syn=xml fen fdm=syntax fdl=2 si -vim: et tw=78 syn=sgml -vi: ts=1 sw=1 ---> +?> +]]> + +</programlisting> +</example> +</refsect1> + +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-executeMultiple-attributes:t +sgml-indent-step:1 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:"../../../../manual.ced" +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +vim600: syn=xml fen fdm=syntax fdl=2 si +vim: et tw=78 syn=sgml +vi: ts=1 sw=1 +-->