1 <?php
2
3 /*
4 * This file is part of the ICanBoogie package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace ICanBoogie\Mailer;
13
14 /**
15 * Delivers emails into multiple files based on the destination address. Each file is appended to
16 * if it already exists.
17 */
18 class FileDeliverer implements Deliverer
19 {
20 protected $location;
21
22 public function __construct($location)
23 {
24 $this->location = $location;
25 }
26
27 public function deliver(Message $message)
28 {
29 $location = $this->location . DIRECTORY_SEPARATOR;
30
31 if (!file_exists($location))
32 {
33 mkdir($location);
34 }
35
36 foreach ($message->to as $email => $name)
37 {
38 $fh = fopen($location . $email, 'a');
39
40 fputs($fh, "{$message->header}\r\n{$message}\r\n\r\n");
41 }
42 }
43 }