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

Source for file Email.php

Documentation is available at Email.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: Email.php 152 2010-06-18 07:39:40Z teo $
  11. */
  12.  
  13. /**
  14. * Alternate SMTP and default 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 extends Zend_Mail
  22. {
  23.     /**
  24.      * Mailer
  25.      * @access public
  26.      * @var string 
  27.      */
  28.     public $xmailer = 'DotKernel Mailer';
  29.     /**
  30.      * Email constructor
  31.      * @access public
  32.      * @return Zend_Mail 
  33.      */
  34.     public function __construct()
  35.     {
  36.         $this->settings Zend_Registry::get('settings');
  37.         $this->db Zend_Registry::get('database');
  38.         $this->addHeader('X-Mailer'$this->xmailer);    
  39.         $seo new Dot_Seo();
  40.         $this->seoOption $seo->getOption();    
  41.     }
  42.     /**
  43.      * Set content
  44.      * @access public
  45.      * @param string $content 
  46.      * @param string $format [optional]
  47.      * @return void 
  48.      */
  49.     public function setContent ($content$format 'text/plain')
  50.     {
  51.         if ($format == 'text/html' )
  52.         {
  53.             parent::setBodyHtml($content);
  54.         }
  55.         else
  56.         {
  57.             parent::setBodyText($content);
  58.         }
  59.     }
  60.     
  61.     /**
  62.      * Send email. Parameter is included only to be compatible with Zend_Mail
  63.      * @access public
  64.      * @param  Zend_Mail_Transport_Abstract $transport [optional]
  65.      * @return bool 
  66.      */
  67.     public function send($transport null)
  68.     {        
  69.         // set From and ReplyTo, in case we forgot it in code
  70.         parent::setDefaultFrom($this->settings->siteEmail$this->seoOption->siteName);
  71.         parent::setDefaultReplyTo($this->settings->siteEmail$this->seoOption->siteName);
  72.         //  set the sendmail transporter as default 
  73.         $tr new Dot_Email_Sendmail($this->_from);            
  74.         // check if we need to use an external SMTP
  75.         if('1' == $this->settings->smtpActive)
  76.         {
  77.             $partial @explode('@'$this->_to[0]);
  78.             if(stristr($this->settings->smtpAddresses$partial['1']!== FALSE)
  79.             {
  80.                 $tr new Dot_Email_Smtp();
  81.                 if(empty($tr->smtpData))
  82.                 {
  83.                     // we can't use SMTP in this case 
  84.                     $tr new Dot_Email_Sendmail($this->_from);    
  85.                 }
  86.             }
  87.         }
  88.         $this->setDefaultTransport($tr->getTransport());        
  89.         //try to send the email
  90.         try
  91.         {
  92.             parent::send();
  93.             return TRUE;
  94.         }
  95.         catch (Zend_Exception $e)
  96.         {
  97.             /**
  98.              * @todo definitely we want to create an exception class, Other code to recover from the error
  99.              */
  100.             $devEmails @explode(','$this->settings->devEmails);
  101.             $dateNow date('F dS, Y h:i:s A');
  102.             $mailSubject  "SMTP Error on "$this->seoOption->siteName;
  103.             $mailContent  "We were unable to send SMTP email."."\n";
  104.             $mailContent .= "---------------------------------"."\n";
  105.             $mailContent .="Caught exception: "get_class($e)."\n";
  106.             $mailContent .="Message:  ".$e->getMessage()."\n";
  107.             $mailContent .= "---------------------------------"."\n\n";
  108.             $to $this->getRecipients();
  109.             $mailContent .="To Email: ".$to[0]."\n";
  110.             $mailContent .="From Email: ".$this->getFrom()."\n";
  111.             $mailContent .="Date: ".$dateNow ."\n";
  112.             $mailHeader   "From: ".$this->settings->siteEmail."\r\n";
  113.             $mailHeader  .= "Reply-To:".$this->settings->siteEmail."\r\n"."X-Mailer: PHP/".phpversion();
  114.             foreach($devEmails as $ky => $mailTo)
  115.             {
  116.                 mail($mailTo$mailSubject$mailContent$mailHeader);
  117.             }
  118.             return FALSE;
  119.         }
  120.     }
  121. }

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