ea-Geiercode-base
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file mail.class.php

Documentation is available at mail.class.php

  1. <?php 
  2. /**
  3.  * mail wrapper class
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage code/base
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: mail.class.php 138 2007-08-29 12:13:55Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * path to mail library
  29.  * @ignore
  30.  *  attention: might have been defined already in
  31.  *  config/config.php or code/config.php
  32.  */
  33. if (!defined('eaSWIFT_DIR')) 
  34.     define('eaSWIFT_DIR''3party/swift/Swift-3.1.3-php4/lib');
  35.  
  36. /**
  37.  * path to mail library
  38.  */
  39. if (!defined('SWIFT_ABS_PATH')) 
  40.     define('SWIFT_ABS_PATH'eaSWIFT_DIR);
  41.  
  42. /**
  43.  * load swift library
  44.  */
  45. require_once(eaSWIFT_DIR '/Swift.php');
  46.  
  47. /**
  48.  * load swift connection library
  49.  */
  50. require_once(eaSWIFT_DIR '/Swift/Connection/SMTP.php');
  51.  
  52. /**
  53.  * mail wrapper library
  54.  *
  55.  * @package       ea-Geier
  56.  */
  57. class eaMail {
  58.  
  59.     /**
  60.      * swift resource
  61.      *
  62.      * @var object 
  63.      */
  64.     var $_swift = false;
  65.  
  66.     /**
  67.      * message resource
  68.      *
  69.      * @var object 
  70.      */
  71.     var $_message = false;
  72.  
  73.     /**
  74.      * recipients resource
  75.      *
  76.      * @var object 
  77.      */
  78.     var $_recipients = false;
  79.  
  80.     /**
  81.      * from address resource
  82.      *
  83.      * @var object 
  84.      */
  85.     var $_from = false;
  86.  
  87.     /**
  88.      * error message
  89.      *
  90.      * @var string 
  91.      */
  92.     var $error = false;
  93.  
  94.  
  95.     /**
  96.      * constructor of mail wrapper
  97.      *
  98.      * defines the environmental settings
  99.      * @param    string    server address
  100.      * @param    integer server port (25)
  101.      */
  102.     function eaMail($server$port 25{
  103.         $connection new Swift_Connection_SMTP($server$port);
  104.         $e false;
  105.         Swift_Errors::expect($e'Swift_Connection_Exception')// before 3.3
  106.         Swift_Errors::expect($e'Swift_ConnectionException');
  107.         $connection->start();
  108.         if ($e{
  109.             $this->error = $e->getMessage();
  110.             return false;
  111.         }
  112.         
  113.         $this->_swift =new Swift($connection);
  114.         $this->_message =new Swift_Message();
  115.     }
  116.     
  117.     /**
  118.      * subject setup
  119.      *
  120.      * @param    string    subject
  121.      * @return    boolean status
  122.      */
  123.     function subject($subject{
  124.         if (!$this->_message{
  125.             $this->error = 'message object missing';
  126.             return false;
  127.         }
  128.         $this->_message->setSubject($subject);
  129.         return true;
  130.     }
  131.     
  132.     /**
  133.      * body text setup
  134.      *
  135.      * @param    string    body text
  136.      * @return    boolean status
  137.      */
  138.     function text($text{
  139.         if (!$this->_message{
  140.             $this->error = 'message object missing';
  141.             return false;
  142.         }
  143.         $this->_message->setBody($text);
  144.         return true;
  145.     }
  146.     
  147.     /**
  148.      * recipient setup
  149.      *
  150.      * @param    string    email address
  151.      * @param    string    name
  152.      * @return    boolean status
  153.      */
  154.     function to($address$name ''{
  155.         if (!$this->_recipients$this->_recipients =new Swift_RecipientList();
  156.         $this->_recipients->addTo($address$name);
  157.         return true;
  158.     }
  159.             
  160.     /**
  161.      * carbon-copy recipient setup
  162.      *
  163.      * @param    string    email address
  164.      * @param    string    name
  165.      * @return    boolean status
  166.      */
  167.     function cc($address$name ''{
  168.         if (!$this->_recipients$this->_recipients =new Swift_RecipientList();
  169.         $this->_recipients->addCC($address$name);
  170.         return true;
  171.     }
  172.     
  173.     /**
  174.      * blind copy setup
  175.      *
  176.      * @param    string    email address
  177.      * @param    string    name
  178.      * @return    boolean status
  179.      */
  180.     function bcc($address$name ''{
  181.         if (!$this->_recipients$this->_recipients =new Swift_RecipientList();
  182.         $this->_recipients->addBcc($address$name);
  183.         return true;
  184.     }
  185.     
  186.     /**
  187.      * sender address setup
  188.      *
  189.      * @param    string    email address
  190.      * @param    string    name
  191.      * @return    boolean status
  192.      */
  193.     function from($address$name ''{
  194.         $this->_from =new Swift_Address($address$name);
  195.         return true;
  196.     }
  197.  
  198.     /**
  199.      * send email
  200.      *
  201.      * @return    boolean status
  202.      */
  203.     function send({
  204.         if (!$this->_message{
  205.             $this->error = 'message object missing';
  206.             return false;
  207.         }
  208.         if (!$this->_message->getSubject()) {
  209.             $this->error = 'subject missing';
  210.             return false;
  211.         }
  212.         if (!$this->_message->getBody()) {
  213.             $this->error = 'body missing';
  214.             return false;
  215.         }
  216.         if (!$this->_recipients{
  217.             $this->error = 'recipients missing';
  218.             return false;
  219.         }
  220.         if (!$this->_from{
  221.             $this->error = 'sender address missing';
  222.             return false;
  223.         }
  224.         return $this->_swift->send($this->_message$this->_recipients$this->_from);
  225.     }
  226. }
  227.     
  228. ?>

Documentation generated on Sun, 09 Sep 2007 17:09:07 +0200 by phpDocumentor 1.3.1