diff --git a/FAQ.md b/FAQ.md new file mode 100644 index 0000000..2f3d42e --- /dev/null +++ b/FAQ.md @@ -0,0 +1,9 @@ +# Frequently asked questions # + +**1. It is written on your website that script doesn't use any database for scheduling mails. Then how is it doing that?** + +We wanted to avoid any extra system requirements so it was simpler to use file system instead. Each mail is encoded in JSON (that's where PHP 5.2.0 or greater requirement comes from) and saved as a separate file. + +**2. Is there a facility in your script which allows admin/script installer to set/limit number of mails to be sent in 1 hour? After that script will queue rest of the mails and send it when limit gets reset.** + +There is a somewhat similar facility. You can define how many mails you want to be sent in each cron run. For example, you can set your cron to run every 10 minutes and each time send at most 20 mails. You can limit the number of mails sent in one hour only if cron runs once an hour. You set the number of mails sent in properties file, and you set up cron using whatever is provided on your hosting system. \ No newline at end of file diff --git a/PageName.md b/PageName.md new file mode 100644 index 0000000..519e8a6 --- /dev/null +++ b/PageName.md @@ -0,0 +1,24 @@ +# Installation instructions # + +In short, you have to do the following three steps: + +**1. Copy source files** + +Source control contains the following files: + +**`mail_queue`** - folder where actual mails are queued. This folder contains the file called `dummy` which can be deleted. + +**`phpbatchmail.lib.php`** – php source code file where function `batch_mail` is defined. This function takes the same parameters as PHP's function `mail`, and it should be called instead of later one. + +**`mail_next.php`** – PHP script that actually sends queued mails. It should be executed by `cron` as often as you like. + +**`propeties.ini`** – configuration file necessary for `mail_next.php` script. It defines the maximum number of queued mails that are going to be sent in each script run. + +**2. Include `phpbatchmail.lib.php` in your source code and call `batch_mail` instead of `mail`** + +**3. Set up `cron` to run `mail_next.php` as frequent as you want** + +Instructions for this step are different on each hosting environment. If you don’t know how to set up scheduler to run the script in regular intervals, the best would be to ask your hosting provider for help. + + +**That should be it!** \ No newline at end of file diff --git a/ProjectHome.md b/ProjectHome.md new file mode 100644 index 0000000..7addf14 --- /dev/null +++ b/ProjectHome.md @@ -0,0 +1,5 @@ +You are PHP developer and your applications among many other interesting things send e-mails around. However, you are annoyed by the delay that PHP's mail function introduces. Naturally, you would like your scripts to be more responsive to end users. If this is the case, you are at the right spot. + +**Prerequisites:** PHP 5.2.0 or newer, cron access + +**No DB necessary!** \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 66632d5..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -For more details, see the archived web site link available in About section. diff --git a/mail_next.php b/mail_next.php deleted file mode 100644 index 6c59ad8..0000000 --- a/mail_next.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -/******************************************************************************/ -/* Includes */ -/******************************************************************************/ - -include_once(dirname(__FILE__) . "/phpbatchmail.lib.php"); - -/******************************************************************************/ -/* Main */ -/******************************************************************************/ - -$workingDirectory = getcwd(); -chdir(dirname(__FILE__)); - -$properties = parse_ini_file("properties.ini", true); -$i = $properties["General"]["number_of_mails"]; - -if ($handle = opendir("mail_queue")) { - - while (false !== ($file = readdir($handle)) && $i != 0) { - - $fullName = "./mail_queue/" . $file; - - if (is_file($fullName)) { - - $mail = json_decode(file_get_contents($fullName)); - if ($mail) { - if (mail($mail->to, $mail->subject, $mail->message, $mail->headers, $mail->parameters)) { - unlink($fullName); - } - - if ($i > 0) { - --$i; - } - } - } - } - - closedir($handle); -} - -chdir($workingDirectory); - -?> \ No newline at end of file diff --git a/mail_queue/dummy b/mail_queue/dummy deleted file mode 100644 index e69de29..0000000 diff --git a/phpbatchmail.lib.php b/phpbatchmail.lib.php deleted file mode 100644 index 89d5254..0000000 --- a/phpbatchmail.lib.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -/******************************************************************************/ -/* Classes */ -/******************************************************************************/ - -/** - * - * - */ -class Mail { - - public $to; - public $subject; - public $message; - public $headers; - public $parameters; - - /** - * - */ - public function __construct($to, $subject, $message, $headers, $parameters) { - - $this->to = $to; - $this->subject = $subject; - $this->message = $message; - $this->headers = $headers; - $this->parameters = $parameters; - } -} - -/******************************************************************************/ -/* Functions */ -/******************************************************************************/ - - -/** - * For documentation about function parameters see: - * http://www.php.net/manual/en/function.mail.php - * - * Return values: - * TRUE if the mail was successfully queued, FALSE otherwise. - * - * - * @param $to string - * @param $subject string - * @param $message string - * @param $headers string - * @param $parameters string - * @return bool - */ -function batch_mail - ( - $to, - $subject, - $message, - $headers = null, - $parameters = null - ) { - - $mail = new Mail($to, $subject, $message, $headers, $parameters); - - $fileName = dirname(__FILE__) . "/mail_queue/" . date("Ymd_His") . "_" . rand() . ".json"; - $text = json_encode($mail); - - return file_put_contents($fileName, $text); -} - -?> \ No newline at end of file diff --git a/properties.ini b/properties.ini deleted file mode 100644 index 39757aa..0000000 --- a/properties.ini +++ /dev/null @@ -1,5 +0,0 @@ -[General] -; Number of mails sent from queue on each run. -; If the number is equal -1, all mails are sent. -number_of_mails = 20 - \ No newline at end of file