*** empty log message ***
[fa-stable.git] / reporting / includes / class.mail.inc
1 <?php
2 /*
3     Name:           eMail
4     Description:    Simple sending eMail in text and HTML with CC, BCC and attachment
5     Version:        1.0
6     last modified:  2004-05-14
7
8     Autor:          Daniel Käfer
9     Homepage:       http://www.danielkaefer.de
10
11     Leave this header in this file!
12 */
13
14 class email
15 {
16     var $to = array();
17     var $cc = array();
18     var $bcc = array();
19     var $attachment = array();
20     var $boundary = "";
21     var $header = "";
22     var $subject = "";
23     var $body = "";
24
25     function email($name, $mail)
26     {
27         $this->boundary = md5(uniqid(time()));
28         $this->header .= "From: $name <$mail>\n";
29     }
30
31     function to($mail)
32     {
33         $this->to[] = $mail;
34     }
35
36     function cc($mail)
37     {
38         $this->cc[] = $mail;
39     }
40
41     function bcc($mail)
42     {
43         $this->bcc[] = $mail;
44     }
45
46     function attachment($file)
47     {
48                 $this->attachment[] = $file;
49     }
50
51     function subject($subject)
52     {
53         $this->subject = $subject;
54     }
55
56     function text($text)
57     {
58             $this->body = "Content-Type: text/plain; charset=ISO-8859-1\n";
59             $this->body .= "Content-Transfer-Encoding: 8bit\n\n";
60             $this->body .= $text."\n";
61     }
62
63     function html($html)
64     {
65             $this->body = "Content-Type: text/html; charset=ISO-8859-1\n";
66             $this->body .= "Content-Transfer-Encoding: quoted-printable\n\n";
67             $this->body .= "<html><body>\n".$html."\n</body></html>\n";
68     }
69
70         function send()
71     {
72         // CC Empfänger hinzufügen
73         $max = count($this->cc);
74         if ($max > 0)
75         {
76             $this->header .= "Cc: ".$this->cc[0];
77             for ($i = 1; $i < $max; $i++)
78             {
79                 $this->header .= ", ".$this->cc[$i];
80             }
81             $this->header .= "\n";
82         }
83         // BCC Empfänger hinzufügen
84         $max = count($this->bcc);
85         if ($max > 0)
86         {
87             $this->header .= "Bcc: ".$this->bcc[0];
88             for ($i = 1; $i < $max; $i++)
89             {
90                 $this->header .= ", ".$this->bcc[$i];
91             }
92             $this->header .= "\n";
93         }
94         $this->header .= "MIME-Version: 1.0\n";
95             $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\n\n";
96             $this->header .= "This is a multi-part message in MIME format\n";
97         $this->header .= "--$this->boundary\n";
98         $this->header .= $this->body;
99
100         // Attachment hinzufügen
101         $max = count($this->attachment);
102         if ($max > 0)
103         {
104             for ($i = 0; $i < $max; $i++)
105             {
106                 $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
107                 $this->header .= "--".$this->boundary."\n";
108                 $this->header .= "Content-Type: application/x-zip-compressed; name=".basename($this->attachment[$i])."\n";
109                 $this->header .= "Content-Transfer-Encoding: base64\n";
110                 $this->header .= "Content-Disposition: attachment; filename=".basename($this->attachment[$i])."\n\n";
111                 $this->header .= chunk_split(base64_encode($file))."\n";
112                 $file = "";
113             }
114         }
115         $this->header .= "--".$this->boundary."--\n\n";
116
117         foreach($this->to as $mail)
118         {
119             $ret = mail($mail, $this->subject, "", $this->header);
120         }
121         return $ret;
122     }
123 }
124 ?>