2004-07-15 14:40:07 +02:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
< html > < head > < meta http-equiv = "Content-Type" content = "text/html;charset=iso-8859-1" >
< title > dolibarr: htdocs/lib/CMailFile.class.php Source File< / title >
< link href = "doxygen.css" rel = "stylesheet" type = "text/css" >
< / head > < body >
<!-- G<> n<EFBFBD> r<EFBFBD> par Doxygen 1.3.7 -->
2004-07-15 20:43:48 +02:00
< div class = "qindex" > < a class = "qindex" href = "index.html" > Page principale< / a > | < a class = "qindex" href = "classes.html" > Liste alphab<EFBFBD> tique< / a > | < a class = "qindex" href = "annotated.html" > Liste des classes< / a > | < a class = "qindex" href = "files.html" > Liste des fichiers< / a > | < a class = "qindex" href = "functions.html" > Membres de classe< / a > | < a class = "qindex" href = "globals.html" > Membres de fichier< / a > < / div >
2004-07-16 00:17:39 +02:00
< h1 > htdocs/lib/CMailFile.class.php< / h1 > < a href = "CMailFile_8class_8php.html" > Aller <20> la documentation de ce fichier.< / a > < pre class = "fragment" > < div > 00001 < ?php
2004-07-15 14:40:07 +02:00
00002 < span class = "comment" > /* notes from Dan Potter:< / span >
00003 < span class = "comment" > Sure. I changed a few other things in here too though. One is that I let< / span >
00004 < span class = "comment" > you specify what the destination filename is (i.e., what is shows up as in< / span >
00005 < span class = "comment" > the attachment). This is useful since in a web submission you often can't< / span >
00006 < span class = "comment" > tell what the filename was supposed to be from the submission itself. I< / span >
00007 < span class = "comment" > also added my own version of chunk_split because our production version of< / span >
00008 < span class = "comment" > PHP doesn't have it. You can change that back or whatever though =).< / span >
00009 < span class = "comment" > Finally, I added an extra "\n" before the message text gets added into the< / span >
00010 < span class = "comment" > MIME output because otherwise the message text wasn't showing up.< / span >
00011 < span class = "comment" > /*< / span >
00012 < span class = "comment" > note: someone mentioned a command-line utility called 'mutt' that < / span >
00013 < span class = "comment" > can mail attachments.< / span >
00014 < span class = "comment" > */< / span >
00015 < span class = "comment" > /* < / span >
00016 < span class = "comment" > If chunk_split works on your system, change the call to my_chunk_split< / span >
00017 < span class = "comment" > to chunk_split < / span >
00018 < span class = "comment" > */< / span >
00019 < span class = "comment" > /* Note: if you don't have base64_encode on your sytem it will not work */< / span >
00020
2004-07-16 00:17:39 +02:00
00039 < span class = "comment" > // simple class that encapsulates mail() with addition of mime file attachment.< / span >
< a name = "l00040" > < / a > < a class = "code" href = "classCMailFile.html" > 00040< / a > < span class = "keyword" > class < / span > < a class = "code" href = "classCMailFile.html" > CMailFile< / a >
00041 {
00042 var $subject;
00043 var $addr_to;
00044 var $addr_cc;
00045 var $text_body;
00046 var $text_encoded;
00047 var $mime_headers;
00048 var $mime_boundary = < span class = "stringliteral" > "--==================_846811060==_"< / span > ;
00049 var $smtp_headers;
00050
00063 < span class = "comment" > // CMail("sujet","email_to","email_from","email_msg",tableau du path de fichiers,tableau de type mime,tableau de noms fichiers,"chaine cc")< / span >
< a name = "l00064" > < / a > < a class = "code" href = "classCMailFile.html#a0" > 00064< / a > function < a class = "code" href = "classCMailFile.html" > CMailFile< / a > ($subject,$to,$from,$msg,$filename_list,$mimetype_list,$mimefilename_list,$addr_cc = < span class = "stringliteral" > ""< / span > )
00065 {
00066 $this-> subject = $subject;
00067 $this-> addr_to = $to;
2004-07-16 08:41:58 +02:00
00068 $this-> smtp_headers = $this-> < a class = "code" href = "classCMailFile.html#a6" > write_smtpheaders< / a > ($from,$addr_cc);
00069 $this-> text_body = $this-> < a class = "code" href = "classCMailFile.html#a4" > write_body< / a > ($msg, $filename_list);
2004-07-16 00:17:39 +02:00
00070 < span class = "keywordflow" > if< / span > (count($filename_list)) {
2004-07-16 08:41:58 +02:00
00071 $this-> mime_headers = $this-> < a class = "code" href = "classCMailFile.html#a5" > write_mimeheaders< / a > ($filename_list, $mimefilename_list);
00072 $this-> text_encoded = $this-> < a class = "code" href = "classCMailFile.html#a1" > attach_file< / a > ($filename_list,$mimetype_list,$mimefilename_list);
2004-07-16 00:17:39 +02:00
00073 }
00074 }
00075
2004-07-16 08:41:58 +02:00
< a name = "l00083" > < / a > < a class = "code" href = "classCMailFile.html#a1" > 00083< / a > function < a class = "code" href = "classCMailFile.html#a1" > attach_file< / a > ($filename_list,$mimetype_list,$mimefilename_list)
00084 {
00085 < span class = "keywordflow" > for< / span > ($i = 0; $i < count($filename_list); $i++) {
00086 $encoded = $this-> < a class = "code" href = "classCMailFile.html#a2" > encode_file< / a > ($filename_list[$i]);
00087 < span class = "keywordflow" > if< / span > ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
00088 $out = $out . < span class = "stringliteral" > "--"< / span > . $this-> mime_boundary . < span class = "stringliteral" > "\n"< / span > ;
00089 < span class = "keywordflow" > if< / span > (! $mimetype_list[$i]) { $mimetype_list[$i] = < span class = "stringliteral" > "application/octet-stream"< / span > ; }
00090 $out = $out . < span class = "stringliteral" > "Content-type: "< / span > . $mimetype_list[$i] . < span class = "stringliteral" > "; name=\"$filename_list[$i]\";\n"< / span > ;
00091 $out = $out . < span class = "stringliteral" > "Content-Transfer-Encoding: base64\n"< / span > ;
00092 $out = $out . < span class = "stringliteral" > "Content-disposition: attachment; filename=\"$filename_list[$i]\"\n\n"< / span > ;
00093 $out = $out . $encoded . < span class = "stringliteral" > "\n"< / span > ;
00094 }
00095 $out = $out . < span class = "stringliteral" > "--"< / span > . $this-> mime_boundary . < span class = "stringliteral" > "--"< / span > . < span class = "stringliteral" > "\n"< / span > ;
00096 < span class = "keywordflow" > return< / span > $out;
00097 < span class = "comment" > // added -- to notify email client attachment is done< / span >
00098 }
00099
< a name = "l00105" > < / a > < a class = "code" href = "classCMailFile.html#a2" > 00105< / a > function < a class = "code" href = "classCMailFile.html#a2" > encode_file< / a > ($sourcefile)
00106 {
00107 < span class = "comment" > // print "< pre> on encode $sourcefile < /pre> \n";< / span >
00108 < span class = "keywordflow" > if< / span > (is_readable($sourcefile))
00109 {
00110 $fd = fopen($sourcefile, < span class = "stringliteral" > "r"< / span > );
00111 $contents = fread($fd, filesize($sourcefile));
00112 $encoded = < a class = "code" href = "CMailFile_8class_8php.html#a0" > my_chunk_split< / a > (base64_encode($contents));
00113 fclose($fd);
00114 }
00115 < span class = "keywordflow" > return< / span > $encoded;
00116 }
00117
< a name = "l00122" > < / a > < a class = "code" href = "classCMailFile.html#a3" > 00122< / a > function < a class = "code" href = "classCMailFile.html#a3" > sendfile< / a > ()
00123 {
00124 $headers .= $this-> smtp_headers . $this-> mime_headers;
00125 $message = $this-> text_body . $this-> text_encoded;
00126 < span class = "keywordflow" > return< / span > mail($this-> addr_to,$this-> subject,stripslashes($message),$headers);
00127 }
00128
< a name = "l00135" > < / a > < a class = "code" href = "classCMailFile.html#a4" > 00135< / a > function < a class = "code" href = "classCMailFile.html#a4" > write_body< / a > ($msgtext, $filename_list)
00136 {
00137 < span class = "keywordflow" > if< / span > (count($filename_list))
00138 {
00139 $out = < span class = "stringliteral" > "--"< / span > . $this-> mime_boundary . < span class = "stringliteral" > "\n"< / span > ;
00140 $out = $out . < span class = "stringliteral" > "Content-Type: text/plain; charset=\"iso8859-15\"\n\n"< / span > ;
00141 < span class = "comment" > // $out = $out . "Content-Type: text/plain; charset=\"us-ascii\"\n\n";< / span >
00142 }
00143 $out = $out . $msgtext . < span class = "stringliteral" > "\n"< / span > ;
00144 < span class = "keywordflow" > return< / span > $out;
00145 }
00146
< a name = "l00153" > < / a > < a class = "code" href = "classCMailFile.html#a5" > 00153< / a > function < a class = "code" href = "classCMailFile.html#a5" > write_mimeheaders< / a > ($filename_list, $mimefilename_list) {
00154 $out = < span class = "stringliteral" > "MIME-version: 1.0\n"< / span > ;
00155 $out = $out . < span class = "stringliteral" > "Content-type: multipart/mixed; "< / span > ;
00156 $out = $out . < span class = "stringliteral" > "boundary=\"$this-> mime_boundary\"\n"< / span > ;
00157 $out = $out . < span class = "stringliteral" > "Content-transfer-encoding: 7BIT\n"< / span > ;
00158 < span class = "keywordflow" > for< / span > ($i = 0; $i < count($filename_list); $i++) {
00159 < span class = "keywordflow" > if< / span > ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
00160 $out = $out . < span class = "stringliteral" > "X-attachments: $filename_list[$i];\n\n"< / span > ;
00161 }
00162 < span class = "keywordflow" > return< / span > $out;
00163 }
00164
< a name = "l00171" > < / a > < a class = "code" href = "classCMailFile.html#a6" > 00171< / a > function < a class = "code" href = "classCMailFile.html#a6" > write_smtpheaders< / a > ($addr_from,$addr_cc)
00172 {
00173 $out = < span class = "stringliteral" > "From: $addr_from\n"< / span > ;
00174 < span class = "keywordflow" > if< / span > ($addr_cc != < span class = "stringliteral" > ""< / span > )
00175 $out = $out . < span class = "stringliteral" > "Cc: $addr_cc\n"< / span > ;
00176 $out = $out . < span class = "stringliteral" > "Reply-To: $addr_from\n"< / span > ;
00177 $out = $out . < span class = "stringliteral" > "X-Mailer: Dolibarr version "< / span > . DOL_VERSION .< span class = "stringliteral" > "\n"< / span > ;
00178 $out = $out . < span class = "stringliteral" > "X-Sender: $addr_from\n"< / span > ;
00179 < span class = "keywordflow" > return< / span > $out;
00180 }
00181 }
00182
00190 < span class = "comment" > // usage - mimetype example "image/gif"< / span >
00191 < span class = "comment" > // $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filename,$mimetype);< / span >
00192 < span class = "comment" > // $mailfile-> sendfile();< / span >
00193
00194 < span class = "comment" > // Splits a string by RFC2045 semantics (76 chars per line, end with \r\n).< / span >
00195 < span class = "comment" > // This is not in all PHP versions so I define one here manuall.< / span >
00196
< a name = "l00197" > < / a > < a class = "code" href = "CMailFile_8class_8php.html#a0" > 00197< / a > function < a class = "code" href = "CMailFile_8class_8php.html#a0" > my_chunk_split< / a > ($str)
00198 {
00199 $stmp = $str;
00200 $len = strlen($stmp);
00201 $out = < span class = "stringliteral" > ""< / span > ;
00202 < span class = "keywordflow" > while< / span > ($len > 0) {
00203 < span class = "keywordflow" > if< / span > ($len > = 76) {
00204 $out = $out . substr($stmp, 0, 76) . < span class = "stringliteral" > "\r\n"< / span > ;
00205 $stmp = substr($stmp, 76);
00206 $len = $len - 76;
00207 }
00208 < span class = "keywordflow" > else< / span > {
00209 $out = $out . $stmp . < span class = "stringliteral" > "\r\n"< / span > ;
00210 $stmp = < span class = "stringliteral" > ""< / span > ; $len = 0;
00211 }
00212 }
00213 < span class = "keywordflow" > return< / span > $out;
00214 }
00215
00216 < span class = "comment" > // end script< / span >
00217 ?>
< / div > < / pre > < hr size = "1" > < address style = "align: right;" > < small > G<EFBFBD> n<EFBFBD> r<EFBFBD> le Fri Jul 16 08:51:51 2004 pour dolibarr par
2004-07-15 14:40:07 +02:00
< a href = "http://www.doxygen.org/index.html" >
< img src = "doxygen.png" alt = "doxygen" align = "middle" border = 0 > < / a > 1.3.7 < / small > < / address >
< / body >
< / html >