DotLibrary
[ class tree: DotLibrary ] [ index: DotLibrary ] [ all elements ]

Source for file Smtp.php

Documentation is available at Smtp.php

  1. <?php
  2. /**
  3. * DotBoost Technologies Inc.
  4. * DotKernel Application Framework
  5. *
  6. @category   DotKernel
  7. @package    DotLibrary
  8. @copyright  Copyright (c) 2009 DotBoost  Technologies (http://www.dotboost.com)
  9. @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  10. @version    $Id: Smtp.php 158 2010-06-25 08:59:20Z teo $
  11. */
  12.  
  13. /**
  14. * Alternate SMTP server mail() class
  15. @category   DotKernel
  16. @package    DotLibrary
  17. @subpackage DotEmail
  18. @author     DotKernel Team <team@dotkernel.com>
  19. */
  20.  
  21. class Dot_Email_Smtp extends Dot_Email
  22. {
  23.     /**
  24.      * Email constructor
  25.      * @access public
  26.      * @param string $to [optional]
  27.      * @param string $fromName [optional]
  28.      * @param string $fromEmail [optional]
  29.      * @param string $subject [optional]
  30.      * @return Dot_Email_Smtp 
  31.      */
  32.     public function __construct($to null$fromName null$fromEmail null$subject null)
  33.     {
  34.         $this->db Zend_Registry::get('database');
  35.         $this->smtpData $this->getSMTP();
  36.         // check if we still have available SMTP connections for today
  37.         if(!empty($this->smtpData))
  38.         {
  39.             $mailConfigs array('auth' => 'login',
  40.                                            'username' => $this->smtpData['smtpUsername'],
  41.                                            'password' => $this->smtpData['smtpPassword'],
  42.                                            'port' => $this->smtpData['smtpPort'],
  43.                                            'ssl' => $this->smtpData['smtpSsl']);
  44.             $this->transport new Zend_Mail_Transport_Smtp($this->smtpData['smtpServer']$mailConfigs);    
  45.         }
  46.     }    
  47.     /**
  48.      * Return the transporter
  49.      * @access public
  50.      * @return Zend_Mail_Transport_Smtp 
  51.      */
  52.     public function getTransport()
  53.     {
  54.         $this->updateSMTPCounter($this->smtpData['id']);
  55.         return $this->transport;
  56.     }
  57.     /**
  58.      * Get the current SMTP info for sending the email
  59.      * @access private
  60.      * @return array 
  61.      */
  62.     private function getSMTP ()
  63.     {
  64.         $smtp array();
  65.         $select $this->db->select()
  66.                            ->from('emailTransporter'
  67.                                            array('id'
  68.                                                 'smtpUsername' => 'user',
  69.                                                 'smtpPassword' => 'pass',
  70.                                                 'smtpServer' => 'server',
  71.                                                 'smtpPort' => 'port',
  72.                                                 'smtpSsl' => 'ssl'))
  73.                            ->where('counter < capacity')
  74.                            ->where('isActive = ?','1')
  75.                            ->order('id')
  76.                            ->limit('1');
  77.         $result $this->db->fetchAll($select);    
  78.         if (count($result0)
  79.         {            
  80.             $smtp $result[0];            
  81.         }
  82.         else
  83.         {
  84.             $where array(" `date` < DATE_FORMAT( NOW( ) , '%Y-%m-%d' )","isActive = '1'");
  85.             $this->db->update('emailTransporter'array('counter'=>0)$where);
  86.             $this->db->update('emailTransporter'array('date'=>new Zend_Db_Expr('NOW()'))$where);
  87.             $select->where("`date` = DATE_FORMAT( NOW( ) , '%Y-%m-%d' )");
  88.             $result $this->db->fetchAll($select);    
  89.             if (count($result0)
  90.             {            
  91.                 $smtp $result[0];                
  92.             }
  93.         }
  94.         return $smtp;
  95.     }
  96.     /**
  97.      * Update the counter of the current transporter.
  98.      * @access private
  99.      * @param int $id 
  100.      * @return void 
  101.      */
  102.     private function updateSMTPCounter ($id)
  103.     {
  104.         $this->db->update('emailTransporter'array('counter' => new Zend_Db_Expr('counter+1'))'id = '.$id);
  105.     }
  106. }

Documentation generated on Wed, 21 Jul 2010 07:34:43 +0000 by phpDocumentor 1.4.3