Changeset 393


Ignore:
Timestamp:
Mar 1, 2012, 9:55:39 PM (13 years ago)
Author:
chronos
Message:
  • Testování odesílání pošty s přílohou.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mail.php

    r392 r393  
    11<?php
     2
     3define(DISPOSITION_INLINE, 'inline');
     4define(DISPOSITION_ATTACHMENT, 'attachment');
     5
     6define(CHARSET_ASCII, 'us-ascii');
     7define(CHARSET_UTF8, 'utf-8');
    28
    39class Mail
    410{
    5   var $sendto = array();
     11  var $SendTo = array();
    612  var $acc = array();
    713  var $abcc = array();
     
    5460  {
    5561    // 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);
    6066  }
    6167
    6268  function Cc($cc)
    6369  {
    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;
    6672               
    6773    if($this->checkAddress == true) $this->CheckAdresses($this->acc);   
     
    8288  }
    8389
    84   function Body($body, $charset='')
     90  function Body($body, $charset = '')
    8591  {
    8692    $this->body = $body;
     
    8995    {
    9096      $this->charset = strtolower($charset);
    91       if($this->charset != 'us-ascii') $this->ctencoding = '8bit';
     97      if($this->charset != CHARSET_ASCII) $this->ctencoding = '8bit';
    9298    }
    9399  }
     
    108114  }
    109115
    110   function Attach( $filename, $filetype = '', $disposition = 'inline')
     116  function Attach($filename, $filetype = '', $disposition = DISPOSITION_ATTACHMENT)
    111117  {
    112118    // TODO : si filetype="", alors chercher dans un tablo de MT connus / extension du fichier
     
    118124  }
    119125
    120   function BuildMail()
     126  private function BuildMail()
    121127  {
    122128    // build the headers
     
    149155    if( count( $this->aattach ) > 0 )
    150156    {
    151       $this->_build_attachement();
     157      $this->BuildAttachement();
    152158    } else
    153159    {
     
    165171  {
    166172    $this->BuildMail();
    167     $this->strTo = implode(', ', $this->sendto );
     173    $this->strTo = implode(', ', $this->SendTo );
    168174       
    169175    // envoie du mail
     
    182188  function ValidEmail($address)
    183189  {
    184     if( ereg( ".*<(.+)>", $address, $regs ) )
     190    if(ereg( ".*<(.+)>", $address, $regs ))
    185191    {
    186192      $address = $regs[1];
    187193    }
    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);
    190196      else return(false);
    191197  }
     
    193199  function CheckAdresses( $aad )
    194200  {
    195     for($i=0; $i< count($aad); $i++ )
     201    for($i=0; $i< count($aad); $i++)
    196202    {
    197203      if(!$this->ValidEmail($aad[$i]))
    198204      {
    199         throw new Exception("Class Mail, method Mail : invalid address $aad[$i]");     
     205        throw new Exception('Class Mail, method Mail : invalid address '.$aad[$i]);
    200206      }
    201207    }
    202208  }
    203209
    204   function _build_attachement()
     210  private function BuildAttachement()
    205211  {
    206212    $this->xheaders['Content-Type'] = "multipart/mixed;\n boundary=\"$this->boundary\"";
     
    215221       
    216222    // for each attached file, do...
    217     for( $i = 0; $i < count($this->aattach); $i++)
     223    for($i = 0; $i < count($this->aattach); $i++)
    218224    {
    219225      $filename = $this->aattach[$i];
     
    225231      {
    226232        throw new Exception('Class Mail, method attach : file '.$filename.' can\'t be found');
    227       }
     233      } 
    228234      $subhdr = '--'.$this->boundary."\nContent-type: ".$ctype.";\n name=\"".$basename.
    229235        "\"\nContent-Transfer-Encoding: base64\nContent-Disposition: ".$disposition.
  • trunk/temp/mailtest.php

    r392 r393  
    99$Mail->Subject('Zkušební zpráva');
    1010$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');
    1213$Mail->Send();
    1314
Note: See TracChangeset for help on using the changeset viewer.