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();
25 function email($name, $mail)
27 $this->boundary = md5(uniqid(time()));
28 $this->header .= "From: $name <$mail>\n";
46 function attachment($file)
48 $this->attachment[] = $file;
51 function subject($subject)
53 $this->subject = $subject;
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";
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";
72 // CC Empfänger hinzufügen
73 $max = count($this->cc);
76 $this->header .= "Cc: ".$this->cc[0];
77 for ($i = 1; $i < $max; $i++)
79 $this->header .= ", ".$this->cc[$i];
81 $this->header .= "\n";
83 // BCC Empfänger hinzufügen
84 $max = count($this->bcc);
87 $this->header .= "Bcc: ".$this->bcc[0];
88 for ($i = 1; $i < $max; $i++)
90 $this->header .= ", ".$this->bcc[$i];
92 $this->header .= "\n";
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;
100 // Attachment hinzufügen
101 $max = count($this->attachment);
104 for ($i = 0; $i < $max; $i++)
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";
115 $this->header .= "--".$this->boundary."--\n\n";
117 foreach($this->to as $mail)
119 $ret = mail($mail, $this->subject, "", $this->header);