Include jQuery editable plugin
[infodrom.org/service.infodrom.org] / class / mail.class.php
1 <?php
2
3 class Mail {
4   protected $header = array();
5   protected $env_from = false;
6
7   public function set($name, $value)
8   {
9     $this->header[$name][] = $value;
10   }
11
12   public function env_from($value)
13   {
14     $this->env_from = $value;
15   }
16
17   private function content_type($file)
18   {
19     if (($fh = popen('/usr/bin/file -i -b ' . escapeshellarg($file), 'r')) !== false) {
20       $type = fread($fh, 1024);
21       fclose($fh);
22       $parts = explode(';', $type);
23       return trim($parts[0]);
24     } else
25       return mime_content_type($file);
26   }
27
28   public function attach($filename,$basename=false,$content_type=false)
29   {
30   }
31
32   public function send($body)
33   {
34     if (!array_key_exists('From', $this->header))
35       throw new Exception('No sender given.');
36     if (!array_key_exists('To', $this->header))
37       throw new Exception('No recipient given.');
38     if (!array_key_exists('Subject', $this->header))
39       throw new Exception('No subject given.');
40     if (empty($body))
41       throw new Exception('Mail body empty.');
42
43     if (!array_key_exists('Content-Type', $this->header))
44       $this->set('Content-Type', 'text/plain; charset=UTF-8');
45     if (!array_key_exists('Content-Disposition', $this->header))
46       $this->set('Content-Disposition', 'inline');
47     if (!array_key_exists('Content-Transfer-Encoding', $this->header))
48       $this->set('Content-Transfer-Encoding', '8bit');
49
50     $header = '';
51     foreach ($this->header as $name => $values) {
52       if ($name == 'To' || $name == 'Subject')
53         continue;
54       else
55         $header .= $name . ': ' . implode(', ', $values) . "\r\n";
56     }
57
58     $opts = '-t';
59     $opts .= strlen($this->env_from) ? ' -f '.$this->env_from : '';
60     $result = mail(implode(',',$this->header['To']), $this->header['Subject'][0], $body, $header, $opts);
61
62     return $result;
63   }
64 }
65
66 ?>