Changeset 393
- Timestamp:
- Mar 1, 2012, 9:55:39 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mail.php
r392 r393 1 1 <?php 2 3 define(DISPOSITION_INLINE, 'inline'); 4 define(DISPOSITION_ATTACHMENT, 'attachment'); 5 6 define(CHARSET_ASCII, 'us-ascii'); 7 define(CHARSET_UTF8, 'utf-8'); 2 8 3 9 class Mail 4 10 { 5 var $ sendto = array();11 var $SendTo = array(); 6 12 var $acc = array(); 7 13 var $abcc = array(); … … 54 60 { 55 61 // TODO : test validité sur to 56 if(is_array($to)) $this-> sendto= $to;57 else $this-> sendto[] = $to;58 59 if($this->checkAddress == true) $this->CheckAdresses($this-> sendto);62 if(is_array($to)) $this->SendTo = $to; 63 else $this->SendTo[] = $to; 64 65 if($this->checkAddress == true) $this->CheckAdresses($this->SendTo); 60 66 } 61 67 62 68 function Cc($cc) 63 69 { 64 if(is_array($cc)) $this->acc = $cc;65 else $this->acc[] = $cc;70 if(is_array($cc)) $this->acc = $cc; 71 else $this->acc[] = $cc; 66 72 67 73 if($this->checkAddress == true) $this->CheckAdresses($this->acc); … … 82 88 } 83 89 84 function Body($body, $charset ='')90 function Body($body, $charset = '') 85 91 { 86 92 $this->body = $body; … … 89 95 { 90 96 $this->charset = strtolower($charset); 91 if($this->charset != 'us-ascii') $this->ctencoding = '8bit';97 if($this->charset != CHARSET_ASCII) $this->ctencoding = '8bit'; 92 98 } 93 99 } … … 108 114 } 109 115 110 function Attach( $filename, $filetype = '', $disposition = 'inline')116 function Attach($filename, $filetype = '', $disposition = DISPOSITION_ATTACHMENT) 111 117 { 112 118 // TODO : si filetype="", alors chercher dans un tablo de MT connus / extension du fichier … … 118 124 } 119 125 120 function BuildMail()126 private function BuildMail() 121 127 { 122 128 // build the headers … … 149 155 if( count( $this->aattach ) > 0 ) 150 156 { 151 $this-> _build_attachement();157 $this->BuildAttachement(); 152 158 } else 153 159 { … … 165 171 { 166 172 $this->BuildMail(); 167 $this->strTo = implode(', ', $this-> sendto );173 $this->strTo = implode(', ', $this->SendTo ); 168 174 169 175 // envoie du mail … … 182 188 function ValidEmail($address) 183 189 { 184 if( ereg( ".*<(.+)>", $address, $regs ))190 if(ereg( ".*<(.+)>", $address, $regs )) 185 191 { 186 192 $address = $regs[1]; 187 193 } 188 if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) 189 return(true);194 if(ereg( "^[^@ ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address)) 195 return(true); 190 196 else return(false); 191 197 } … … 193 199 function CheckAdresses( $aad ) 194 200 { 195 for($i=0; $i< count($aad); $i++ 201 for($i=0; $i< count($aad); $i++) 196 202 { 197 203 if(!$this->ValidEmail($aad[$i])) 198 204 { 199 throw new Exception( "Class Mail, method Mail : invalid address $aad[$i]");205 throw new Exception('Class Mail, method Mail : invalid address '.$aad[$i]); 200 206 } 201 207 } 202 208 } 203 209 204 function _build_attachement()210 private function BuildAttachement() 205 211 { 206 212 $this->xheaders['Content-Type'] = "multipart/mixed;\n boundary=\"$this->boundary\""; … … 215 221 216 222 // for each attached file, do... 217 for( 223 for($i = 0; $i < count($this->aattach); $i++) 218 224 { 219 225 $filename = $this->aattach[$i]; … … 225 231 { 226 232 throw new Exception('Class Mail, method attach : file '.$filename.' can\'t be found'); 227 } 233 } 228 234 $subhdr = '--'.$this->boundary."\nContent-type: ".$ctype.";\n name=\"".$basename. 229 235 "\"\nContent-Transfer-Encoding: base64\nContent-Disposition: ".$disposition. -
trunk/temp/mailtest.php
r392 r393 9 9 $Mail->Subject('Zkušební zpráva'); 10 10 $Mail->From('chronos@zdechov.net'); 11 $Mail->Body('Toto je zkušební zpráva.'); 11 $Mail->Body('Toto je zkušební zpráva.', 'utf-8'); 12 $Mail->Attach('sugar.php', 'text/plain'); 12 13 $Mail->Send(); 13 14
Note:
See TracChangeset
for help on using the changeset viewer.