From a0fdeca1145290f5e24db17b761e67adc9910494 Mon Sep 17 00:00:00 2001 From: Joey Schulze Date: Fri, 4 Apr 2014 18:20:17 +0000 Subject: [PATCH] Add mail class --- class/mail.class.php | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 class/mail.class.php diff --git a/class/mail.class.php b/class/mail.class.php new file mode 100644 index 0000000..5cfb968 --- /dev/null +++ b/class/mail.class.php @@ -0,0 +1,66 @@ +header[$name][] = $value; + } + + public function env_from($value) + { + $this->env_from = $value; + } + + private function content_type($file) + { + if (($fh = popen('/usr/bin/file -i -b ' . escapeshellarg($file), 'r')) !== false) { + $type = fread($fh, 1024); + fclose($fh); + $parts = explode(';', $type); + return trim($parts[0]); + } else + return mime_content_type($file); + } + + public function attach($filename,$basename=false,$content_type=false) + { + } + + public function send($body) + { + if (!array_key_exists('From', $this->header)) + throw new Exception('No sender given.'); + if (!array_key_exists('To', $this->header)) + throw new Exception('No recipient given.'); + if (!array_key_exists('Subject', $this->header)) + throw new Exception('No subject given.'); + if (empty($body)) + throw new Exception('Mail body empty.'); + + if (!array_key_exists('Content-Type', $this->header)) + $this->set('Content-Type', 'text/plain; charset=UTF-8'); + if (!array_key_exists('Content-Disposition', $this->header)) + $this->set('Content-Disposition', 'inline'); + if (!array_key_exists('Content-Transfer-Encoding', $this->header)) + $this->set('Content-Transfer-Encoding', '8bit'); + + $header = ''; + foreach ($this->header as $name => $values) { + if ($name == 'To' || $name == 'Subject') + continue; + else + $header .= $name . ': ' . implode(', ', $values) . "\r\n"; + } + + $opts = '-t'; + $opts .= strlen($this->env_from) ? ' -f '.$this->env_from : ''; + $result = mail(implode(',',$this->header['To']), $this->header['Subject'][0], $body, $header, $opts); + + return $result; + } +} + +?> \ No newline at end of file -- 2.20.1