00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00026 function html2plain($html) {
00027 $text = html_entity_decode($html);
00028 return trim(strip_tags($text));
00029 }
00030
00031
00036 function plain2html($text) {
00037 $html = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
00038 "<a href=\"\\0\">\\0</a>", $text);
00039 $html = nl2br($html);
00040 return "<HTML><BODY>\n$html\n</BODY></HTML>";
00041 }
00042
00043
00046 class DiogenesMailer {
00048 var $header;
00050 var $body;
00052 var $from;
00054 var $to;
00056 var $cc;
00058 var $bcc;
00060 var $subject;
00062 var $boundary;
00065 var $from_present;
00066
00067
00077 function DiogenesMailer($from, $to, $subject, $multipart=false, $cc="", $bcc="") {
00078 trigger_error("DiogenesMailer class is obsolete, use HermesMailer instead !", E_USER_NOTICE);
00079 $this->from = $from;
00080 $this->from_present = false;
00081 $this->to = ($to == '' ? $from : $to);
00082 $this->cc = $cc;
00083 $this->bcc = $bcc;
00084 $this->subject = $subject;
00085 $this->body = "";
00086 $this->header = "X-Mailer: PHP/" . phpversion()."\n".
00087 "Mime-Version: 1.0\n";
00088 if ($multipart) {
00089 $this->boundary="-=partie_suivante_(".uniqid("").")=-";
00090 $this->header .=
00091 "Content-Type: multipart/alternative;\n".
00092 " boundary=\"{$this->boundary}\"\n";
00093
00094 } else {
00095 $this->boundary="";
00096 $this->header .=
00097 "Content-Type: text/plain; charset=iso-8859-1\n".
00098 "Content-Disposition: inline\n".
00099 "Content-Transfer-Encoding: 8bit\n";
00100 }
00101 }
00102
00103
00110 function addPart($type,$encoding,$value)
00111 {
00112 if ($this->boundary) {
00113 $this->body.=
00114 "--{$this->boundary}\n".
00115 "Content-Type: $type\n".
00116 "Content-Transfer-Encoding: $encoding\n\n";
00117 $this->body .= "$value\n";
00118 } else {
00119 echo "<b>Erreur : addPart s'applique uniquement aux messages multipart!</b>";
00120 }
00121 }
00122
00123
00128 function addHeader($text)
00129 {
00130 if (preg_match('/^From:/i', $text)) $this->from_present = true;
00131 $this->header .= "$text\n";
00132 }
00133
00134
00139 function addPartText($text)
00140 {
00141 $this->addPart("text/plain; charset=iso-8859-1",
00142 "8bit", $text);
00143 }
00144
00145
00150 function addPartHtml($html)
00151 {
00152 $this->addPart("text/html; charset=iso-8859-1",
00153 "8bit", $html);
00154 }
00155
00156
00161 function setBody($text)
00162 {
00163 if (!$this->boundary) {
00164 $this->body = $text;
00165 } else {
00166 die("Error : setBody only applies to inline messages!");
00167 }
00168 }
00169
00170
00173 function send()
00174 {
00175 if(!$this->from_present)
00176 $this->header .= "From: {$this->from}\n";
00177 if ($this->to)
00178 $this->header .= "To: {$this->to}\n";
00179 if ($this->cc)
00180 $this->header .= "Cc: {$this->cc}\n";
00181
00182 $this->header .= "Subject: {$this->subject}\n";
00183 $this->header .= "\n";
00184
00185 if ($this->boundary)
00186 $this->body .= "--{$this->boundary}--\n";
00187
00188 $fp = popen('/usr/sbin/sendmail -oi -f '.escapeshellarg($this->from).' '.escapeshellarg($this->to).' '.escapeshellarg($this->cc).' '.escapeshellarg($this->bcc),'w');
00189 if ($fp) {
00190 if(fwrite($fp, $this->header) == -1) return false;
00191 if(fwrite($fp, $this->body) == -1) return false;
00192 if (pclose($fp) == 0) return true;
00193 }
00194 return false;
00195 }
00196
00197 }
00198
00199 ?>