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";
70 function mime_type($filename)
72 $file = basename($filename, '.zip');
73 if ($filename == $file . '.zip') return 'application/x-zip-compressed';
74 $file = basename($filename, '.pdf');
75 if ($filename == $file . '.pdf') return 'application/pdf';
76 $file = basename($filename, '.csv');
77 if ($filename == $file . '.csv') return 'application/vnd.ms-excel';
78 $file = basename($filename, '.tar');
79 if ($filename == $file . '.tar') return 'application/x-tar';
80 $file = basename($filename, '.tar.gz');
81 if ($filename == $file . '.tar.gz') return 'application/x-tar-gz';
82 $file = basename($filename, '.tgz');
83 if ($filename == $file . '.tgz') return 'application/x-tar-gz';
84 $file = basename($filename, '.gz');
85 if ($filename == $file . '.gz') return 'application/x-gzip';
86 return 'application/unknown';
91 // CC Empfänger hinzufügen
92 $max = count($this->cc);
95 $this->header .= "Cc: ".$this->cc[0];
96 for ($i = 1; $i < $max; $i++)
98 $this->header .= ", ".$this->cc[$i];
100 $this->header .= "\n";
102 // BCC Empfänger hinzufügen
103 $max = count($this->bcc);
106 $this->header .= "Bcc: ".$this->bcc[0];
107 for ($i = 1; $i < $max; $i++)
109 $this->header .= ", ".$this->bcc[$i];
111 $this->header .= "\n";
113 $this->header .= "MIME-Version: 1.0\n";
114 $this->header .= "Content-Type: multipart/mixed; boundary=$this->boundary\n\n";
115 $this->header .= "This is a multi-part message in MIME format\n";
116 $this->header .= "--$this->boundary\n";
117 $this->header .= $this->body;
119 // Attachment hinzufügen
120 $max = count($this->attachment);
123 for ($i = 0; $i < $max; $i++)
125 $file = fread(fopen($this->attachment[$i], "r"), filesize($this->attachment[$i]));
126 $this->header .= "--".$this->boundary."\n";
127 $this->header .= "Content-Type: " .$this->mime_type(basename($this->attachment[$i])). "; name=".basename($this->attachment[$i])."\n";
128 $this->header .= "Content-Transfer-Encoding: base64\n";
129 $this->header .= "Content-Disposition: attachment; filename=".basename($this->attachment[$i])."\n\n";
130 $this->header .= chunk_split(base64_encode($file))."\n";
134 $this->header .= "--".$this->boundary."--\n\n";
136 foreach($this->to as $mail)
138 $ret = mail($mail, $this->subject, "", $this->header);