4 Description: Simple sending eMail in text and HTML with CC, BCC and attachment
6 last modified: 2004-05-14
9 Homepage: http://www.danielkaefer.de
11 Leave this header in this file!
19 var $attachment = array();
24 var $charset = 'ISO-8859-1';
26 function email($name, $mail)
28 $this->boundary = md5(uniqid(time()));
29 $this->header .= "From: $name <$mail>\n";
47 function attachment($file)
49 $this->attachment[] = $file;
52 function subject($subject)
54 $this->subject = $subject;
59 $this->body = "Content-Type: text/plain; charset={$this->charset}\n";
60 $this->body .= "Content-Transfer-Encoding: 8bit\n\n";
61 $this->body .= $text."\n";
66 $this->body = "Content-Type: text/html; charset={$this->charset}\n";
67 $this->body .= "Content-Transfer-Encoding: quoted-printable\n\n";
68 $this->body .= "<html><body>\n".$html."\n</body></html>\n";
71 function mime_type($filename)
73 $file = basename($filename, '.zip');
74 if ($filename == $file . '.zip') return 'application/x-zip-compressed';
75 $file = basename($filename, '.pdf');
76 if ($filename == $file . '.pdf') return 'application/pdf';
77 $file = basename($filename, '.csv');
78 if ($filename == $file . '.csv') return 'application/vnd.ms-excel';
79 $file = basename($filename, '.tar');
80 if ($filename == $file . '.tar') return 'application/x-tar';
81 $file = basename($filename, '.tar.gz');
82 if ($filename == $file . '.tar.gz') return 'application/x-tar-gz';
83 $file = basename($filename, '.tgz');
84 if ($filename == $file . '.tgz') return 'application/x-tar-gz';
85 $file = basename($filename, '.gz');
86 if ($filename == $file . '.gz') return 'application/x-gzip';
87 return 'application/unknown';
92 // CC Empfänger hinzufügen
93 $max = count($this->cc);
96 $this->header .= "Cc: ".$this->cc[0];
97 for ($i = 1; $i < $max; $i++)
99 $this->header .= ", ".$this->cc[$i];
101 $this->header .= "\n";
103 // BCC Empfänger hinzufügen
104 $max = count($this->bcc);
107 $this->header .= "Bcc: ".$this->bcc[0];
108 for ($i = 1; $i < $max; $i++)
110 $this->header .= ", ".$this->bcc[$i];
112 $this->header .= "\n";
114 $this->header .= "MIME-Version: 1.0\n";
115 $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\n\n";
116 $this->header .= "This is a multi-part message in MIME format\n";
117 $this->header .= "--$this->boundary\n";
118 $this->header .= $this->body;
120 // Attachment hinzufügen
121 $max = count($this->attachment);
124 for ($i = 0; $i < $max; $i++)
126 $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
127 $this->header .= "--".$this->boundary."\n";
128 $this->header .= "Content-Type: " .$this->mime_type(basename($this->attachment[$i])). "; name=".basename($this->attachment[$i])."\n";
129 $this->header .= "Content-Transfer-Encoding: base64\n";
130 $this->header .= "Content-Disposition: attachment; filename=".basename($this->attachment[$i])."\n\n";
131 $this->header .= chunk_split(base64_encode($file))."\n";
135 $this->header .= "--".$this->boundary."--\n\n";
137 foreach($this->to as $mail)
139 $ret = mail($mail, $this->subject, "", $this->header);